From 71af1e77c8621bb7097aaf4eef2a86d8652ee9b5 Mon Sep 17 00:00:00 2001 From: Aleksey Gurtovoy Date: Sun, 27 Jan 2002 13:39:06 +0000 Subject: [PATCH] compile-time ref.hpp header test, initial checkin [SVN r12525] --- ref_ct_test.cpp | 115 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 ref_ct_test.cpp diff --git a/ref_ct_test.cpp b/ref_ct_test.cpp new file mode 100644 index 0000000..d9af429 --- /dev/null +++ b/ref_ct_test.cpp @@ -0,0 +1,115 @@ +// compile-time test for "boost/ref.hpp" header content +// see 'ref_test.cpp' for run-time part + +#include +#include +#include + +namespace { + +template< typename T, typename U > +void ref_test(boost::reference_wrapper) +{ + typedef typename boost::reference_wrapper::type type; + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); +} + +template< typename T > +void assignable_test(T x) +{ + x = x; +} + +template< bool R, typename T > +void is_reference_wrapper_test(T) +{ + BOOST_STATIC_ASSERT(boost::is_reference_wrapper::value == R); +} + +template< typename R, typename Ref > +void cxx_reference_test(Ref) +{ + BOOST_STATIC_ASSERT((boost::is_same::value)); +} + +template< typename R, typename Ref > +void unwrap_reference_test(Ref) +{ + typedef typename boost::unwrap_reference::type type; + BOOST_STATIC_ASSERT((boost::is_same::value)); +} + +} // namespace + +int main() +{ + int i = 0; + int& ri = i; + + int const ci = 0; + int const& rci = ci; + + // 'ref/cref' functions test + ref_test(boost::ref(i)); + ref_test(boost::ref(ri)); + ref_test(boost::ref(ci)); + ref_test(boost::ref(rci)); + + ref_test(boost::cref(i)); + ref_test(boost::cref(ri)); + ref_test(boost::cref(ci)); + ref_test(boost::cref(rci)); + + // test 'assignable' requirement + assignable_test(boost::ref(i)); + assignable_test(boost::ref(ri)); + assignable_test(boost::cref(i)); + assignable_test(boost::cref(ci)); + assignable_test(boost::cref(rci)); + + // 'is_reference_wrapper' test + is_reference_wrapper_test(boost::ref(i)); + is_reference_wrapper_test(boost::ref(ri)); + is_reference_wrapper_test(boost::cref(i)); + is_reference_wrapper_test(boost::cref(ci)); + is_reference_wrapper_test(boost::cref(rci)); + + is_reference_wrapper_test(i); + is_reference_wrapper_test(ri); + is_reference_wrapper_test(ci); + is_reference_wrapper_test(rci); + + // ordinary references/function template arguments deduction test + cxx_reference_test(i); + cxx_reference_test(ri); + cxx_reference_test(ci); + cxx_reference_test(rci); + + cxx_reference_test(i); + cxx_reference_test(ri); + cxx_reference_test(i); + cxx_reference_test(ri); + cxx_reference_test(ci); + cxx_reference_test(rci); + + // 'unwrap_reference' test + unwrap_reference_test(boost::ref(i)); + unwrap_reference_test(boost::ref(ri)); + unwrap_reference_test(boost::cref(i)); + unwrap_reference_test(boost::cref(ci)); + unwrap_reference_test(boost::cref(rci)); + + unwrap_reference_test(i); + unwrap_reference_test(ri); + unwrap_reference_test(ci); + unwrap_reference_test(rci); + unwrap_reference_test(i); + unwrap_reference_test(ri); + unwrap_reference_test(i); + unwrap_reference_test(ri); + unwrap_reference_test(ci); + unwrap_reference_test(rci); + + return 0; +}