From d2a5fd169f464e9ab8c633473162edba9445599c Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Thu, 24 Jan 2002 16:52:06 +0000 Subject: [PATCH] initial checkin [SVN r12481] --- ref_test.cpp | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 ref_test.cpp diff --git a/ref_test.cpp b/ref_test.cpp new file mode 100644 index 0000000..24f9e98 --- /dev/null +++ b/ref_test.cpp @@ -0,0 +1,124 @@ +#if defined(_MSC_VER) && !defined(__ICL) +# pragma warning(disable: 4786) // identifier truncated in debug info +# pragma warning(disable: 4710) // function not inlined +# pragma warning(disable: 4711) // function selected for automatic inline expansion +# pragma warning(disable: 4514) // unreferenced inline removed +#endif + +#include +#include +#include + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +# pragma warning(push, 3) +#endif + +#include + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +# pragma warning(pop) +#endif + + +#define BOOST_INCLUDE_MAIN +#include + +namespace { +using namespace boost; + +template +struct wrapper +{ + // Used to verify implicit conversion + static T* get_pointer(T& x) + { + return &x; + } + + static T const* get_const_pointer(T const& x) + { + return &x; + } + + static void check_type_typedef(...) + { + BOOST_ERROR("expected a reference_wrapper argument"); + } + + template + static void check_type_typedef(boost::reference_wrapper) + { + typedef typename boost::reference_wrapper::type type_typedef; + BOOST_TEST((boost::is_same::value)); + } + + template + static T* passthru(Arg x) + { + check_type_typedef(x); + return get_pointer(x); + } + + template + static T const* cref_passthru(Arg x) + { + check_type_typedef(x); + return get_const_pointer(x); + } + + template + static void test_unwrapped(Arg x) + { + typedef typename unwrap_reference::type unwrapped; + BOOST_TEST((is_same::value)); + } + + template struct select {}; + typedef select constant; + typedef select non_constant; + + static void cref_test(T x, constant) {} + + static void cref_test(T x, non_constant) + { + BOOST_TEST(is_reference_wrapper >::value); + BOOST_TEST(cref_passthru(cref(x)) == &x); + BOOST_TEST(&cref(x).get() == &x); + } + + BOOST_STATIC_CONSTANT( + bool, t_is_constant = boost::is_const::value); + + static void test(T x) + { + BOOST_TEST(passthru(ref(x)) == &x); + + BOOST_TEST((is_same::type,T>::value)); + + BOOST_TEST(&ref(x).get() == &x); + + typedef reference_wrapper wrapped; + BOOST_TEST(is_reference_wrapper::value); + + typedef typename unwrap_reference::type unwrapped_wrapper; + BOOST_TEST((is_same::value)); + + typedef typename unwrap_reference::type unwrapped_self; + BOOST_TEST((is_same::value)); + + cref_test(x, select()); + } +}; + +} // namespace unnamed + +int test_main(int, char * []) +{ + wrapper::test(1); + wrapper::test(1); + BOOST_TEST(!is_reference_wrapper::value); + BOOST_TEST(!is_reference_wrapper::value); + BOOST_TEST(!is_reference_wrapper::value); + BOOST_TEST(!is_reference_wrapper::value); + return 0; +}