mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
Merge some tests for unwrap ([47296], [47297])
[SVN r60290]
This commit is contained in:
parent
b4dee80e61
commit
e30889304c
43
ref_test.cpp
43
ref_test.cpp
@ -68,11 +68,54 @@ struct ref_wrapper
|
||||
}
|
||||
};
|
||||
|
||||
struct copy_counter {
|
||||
static int count_;
|
||||
copy_counter(copy_counter const& other) {
|
||||
++count_;
|
||||
}
|
||||
copy_counter() {}
|
||||
static void reset() { count_ = 0; }
|
||||
static int count() { return copy_counter::count_; }
|
||||
};
|
||||
|
||||
int copy_counter::count_ = 0;
|
||||
|
||||
} // namespace unnamed
|
||||
|
||||
template <class T>
|
||||
void do_unwrap(T t) {
|
||||
|
||||
/* typename unwrap_reference<T>::type& lt = */
|
||||
unwrap_ref(t);
|
||||
|
||||
}
|
||||
|
||||
void unwrap_test() {
|
||||
|
||||
int i = 3;
|
||||
const int ci = 2;
|
||||
|
||||
do_unwrap(i);
|
||||
do_unwrap(ci);
|
||||
do_unwrap(ref(i));
|
||||
do_unwrap(cref(ci));
|
||||
do_unwrap(ref(ci));
|
||||
|
||||
copy_counter cc;
|
||||
BOOST_CHECK(cc.count() == 0);
|
||||
|
||||
do_unwrap(cc);
|
||||
do_unwrap(ref(cc));
|
||||
do_unwrap(cref(cc));
|
||||
|
||||
BOOST_CHECK(cc.count() == 1);
|
||||
BOOST_CHECK(unwrap_ref(ref(cc)).count() == 1);
|
||||
}
|
||||
|
||||
int test_main(int, char * [])
|
||||
{
|
||||
ref_wrapper<int>::test(1);
|
||||
ref_wrapper<int const>::test(1);
|
||||
unwrap_test();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user