diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 new file mode 100644 index 0000000..74fd336 --- /dev/null +++ b/test/Jamfile.v2 @@ -0,0 +1,32 @@ +# Boost.Core Library test Jamfile +# +# Copyright (c) 2014 Peter Dimov +# +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt + +# bring in rules for testing +import testing ; + +test-suite "core" + : + [ run addressof_test.cpp ] + [ run addressof_test2.cpp ] + [ run addressof_np_test.cpp ] + [ run addressof_fn_test.cpp ] + + [ compile-fail checked_delete_fail.cpp ] + + [ compile ref_ct_test.cpp ] + [ run ref_test.cpp ] + + [ run eif_constructors.cpp ] + [ run eif_dummy_arg_disambiguation.cpp ] + [ run eif_lazy.cpp ] + [ run eif_lazy_test.cpp ] + [ run eif_member_templates.cpp ] + [ run eif_namespace_disambiguation.cpp ] + [ run eif_no_disambiguation.cpp ] + [ run eif_partial_specializations.cpp ] + ; diff --git a/test/addressof_fn_test.cpp b/test/addressof_fn_test.cpp new file mode 100644 index 0000000..0d043bf --- /dev/null +++ b/test/addressof_fn_test.cpp @@ -0,0 +1,76 @@ +#include + +#if defined(BOOST_MSVC) +#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 + +// addressof_fn_test.cpp: addressof( f ) +// +// Copyright (c) 2008, 2009 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include + + +void f0() +{ +} + +void f1(int) +{ +} + +void f2(int, int) +{ +} + +void f3(int, int, int) +{ +} + +void f4(int, int, int, int) +{ +} + +void f5(int, int, int, int, int) +{ +} + +void f6(int, int, int, int, int, int) +{ +} + +void f7(int, int, int, int, int, int, int) +{ +} + +void f8(int, int, int, int, int, int, int, int) +{ +} + +void f9(int, int, int, int, int, int, int, int, int) +{ +} + +int main() +{ + BOOST_TEST( boost::addressof( f0 ) == &f0 ); + BOOST_TEST( boost::addressof( f1 ) == &f1 ); + BOOST_TEST( boost::addressof( f2 ) == &f2 ); + BOOST_TEST( boost::addressof( f3 ) == &f3 ); + BOOST_TEST( boost::addressof( f4 ) == &f4 ); + BOOST_TEST( boost::addressof( f5 ) == &f5 ); + BOOST_TEST( boost::addressof( f6 ) == &f6 ); + BOOST_TEST( boost::addressof( f7 ) == &f7 ); + BOOST_TEST( boost::addressof( f8 ) == &f8 ); + BOOST_TEST( boost::addressof( f9 ) == &f9 ); + + return boost::report_errors(); +} diff --git a/test/addressof_np_test.cpp b/test/addressof_np_test.cpp new file mode 100644 index 0000000..9e155d4 --- /dev/null +++ b/test/addressof_np_test.cpp @@ -0,0 +1,50 @@ +// +// Copyright 2013 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include +#include +#include + +#if defined( BOOST_NO_CXX11_NULLPTR ) + +void nullptr_test() +{ +} + +#else + +void nullptr_test() +{ + { + auto x = nullptr; + BOOST_TEST( boost::addressof(x) == &x ); + } + + { + auto const x = nullptr; + BOOST_TEST( boost::addressof(x) == &x ); + } + + { + auto volatile x = nullptr; + BOOST_TEST( boost::addressof(x) == &x ); + } + + { + auto const volatile x = nullptr; + BOOST_TEST( boost::addressof(x) == &x ); + } +} + +#endif + +int main() +{ + nullptr_test(); + return boost::report_errors(); +} diff --git a/test/addressof_test.cpp b/test/addressof_test.cpp new file mode 100644 index 0000000..9619cc3 --- /dev/null +++ b/test/addressof_test.cpp @@ -0,0 +1,94 @@ +// Copyright (C) 2002 Brad King (brad.king@kitware.com) +// Douglas Gregor (gregod@cs.rpi.edu) +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// For more information, see http://www.boost.org + + +#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 + +#include + +template void scalar_test( T * = 0 ) +{ + T* px = new T(); + + T& x = *px; + BOOST_TEST( boost::addressof(x) == px ); + + const T& cx = *px; + const T* pcx = boost::addressof(cx); + BOOST_TEST( pcx == px ); + + volatile T& vx = *px; + volatile T* pvx = boost::addressof(vx); + BOOST_TEST( pvx == px ); + + const volatile T& cvx = *px; + const volatile T* pcvx = boost::addressof(cvx); + BOOST_TEST( pcvx == px ); + + delete px; +} + +template void array_test( T * = 0 ) +{ + T nrg[3] = {1,2,3}; + T (*pnrg)[3] = &nrg; + BOOST_TEST( boost::addressof(nrg) == pnrg ); + + T const cnrg[3] = {1,2,3}; + T const (*pcnrg)[3] = &cnrg; + BOOST_TEST( boost::addressof(cnrg) == pcnrg ); +} + +struct addressable +{ + addressable( int = 0 ) + { + } +}; + +struct useless_type {}; + +class nonaddressable { +public: + + nonaddressable( int = 0 ) + { + } + + void dummy(); // Silence GCC warning: all member of class are private + +private: + + useless_type operator&() const; +}; + +int main() +{ + scalar_test(); + scalar_test(); + scalar_test(); + scalar_test(); + + array_test(); + array_test(); + array_test(); + array_test(); + + return boost::report_errors(); +} diff --git a/test/addressof_test2.cpp b/test/addressof_test2.cpp new file mode 100644 index 0000000..b1c36f8 --- /dev/null +++ b/test/addressof_test2.cpp @@ -0,0 +1,95 @@ +// Copyright (C) 2002 Brad King (brad.king@kitware.com) +// Douglas Gregor (gregod@cs.rpi.edu) +// +// Copyright 2009 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// For more information, see http://www.boost.org + + +#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 + +#include + +template void scalar_test( T * = 0 ) +{ + T* px = new T(); + + T& x = *px; + BOOST_TEST( boost::addressof(x) == px ); + + const T& cx = *px; + const T* pcx = boost::addressof(cx); + BOOST_TEST( pcx == px ); + + volatile T& vx = *px; + volatile T* pvx = boost::addressof(vx); + BOOST_TEST( pvx == px ); + + const volatile T& cvx = *px; + const volatile T* pcvx = boost::addressof(cvx); + BOOST_TEST( pcvx == px ); + + delete px; +} + +template void array_test( T * = 0 ) +{ + T nrg[3] = {1,2,3}; + T (*pnrg)[3] = &nrg; + BOOST_TEST( boost::addressof(nrg) == pnrg ); + + T const cnrg[3] = {1,2,3}; + T const (*pcnrg)[3] = &cnrg; + BOOST_TEST( boost::addressof(cnrg) == pcnrg ); +} + +class convertible { +public: + + convertible( int = 0 ) + { + } + + template operator U () const + { + return U(); + } +}; + +class convertible2 { +public: + + convertible2( int = 0 ) + { + } + + operator convertible2* () const + { + return 0; + } +}; + +int main() +{ + scalar_test(); + scalar_test(); + + array_test(); + array_test(); + + return boost::report_errors(); +} diff --git a/test/checked_delete_fail.cpp b/test/checked_delete_fail.cpp new file mode 100644 index 0000000..41fdc9a --- /dev/null +++ b/test/checked_delete_fail.cpp @@ -0,0 +1,28 @@ +// Boost checked_delete test program ---------------------------------------// + +// Copyright Beman Dawes 2001. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/libs/utility for documentation. + +// Revision History +// 21 May 01 Initial version (Beman Dawes) + +#include // for checked_delete + +// This program demonstrates compiler errors when trying to delete an +// incomplete type. + +namespace +{ + class Incomplete; +} + +int main() +{ + Incomplete * p = 0; + boost::checked_delete(p); // should cause compile time error + boost::checked_array_delete(p); // should cause compile time error + return 0; +} // main diff --git a/test/eif_constructors.cpp b/test/eif_constructors.cpp new file mode 100644 index 0000000..ea82b40 --- /dev/null +++ b/test/eif_constructors.cpp @@ -0,0 +1,61 @@ +// Boost enable_if library + +// Copyright 2003 (c) The Trustees of Indiana University. + +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include +#include +#include + +using boost::enable_if; +using boost::disable_if; +using boost::is_arithmetic; + +struct container { + bool my_value; + + template + container(const T&, const typename enable_if, T>::type * = 0): + my_value(true) {} + + template + container(const T&, const typename disable_if, T>::type * = 0): + my_value(false) {} +}; + +// example from Howard Hinnant (tests enable_if template members of a templated class) +template +struct xstring +{ + template + xstring(It begin, It end, typename + disable_if >::type* = 0) + : data(end-begin) {} + + int data; +}; + + +int main() +{ + + BOOST_TEST(container(1).my_value); + BOOST_TEST(container(1.0).my_value); + + BOOST_TEST(!container("1").my_value); + BOOST_TEST(!container(static_cast(0)).my_value); + + char sa[] = "123456"; + BOOST_TEST(xstring(sa, sa+6).data == 6); + + + return boost::report_errors(); +} + diff --git a/test/eif_dummy_arg_disambiguation.cpp b/test/eif_dummy_arg_disambiguation.cpp new file mode 100644 index 0000000..e72b158 --- /dev/null +++ b/test/eif_dummy_arg_disambiguation.cpp @@ -0,0 +1,45 @@ +// Boost enable_if library + +// Copyright 2003 (c) The Trustees of Indiana University. + +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include +#include +#include + +using boost::enable_if; +using boost::disable_if; +using boost::is_arithmetic; + +template struct dummy { + dummy(int) {}; +}; + +template +typename enable_if, bool>::type +arithmetic_object(T t, dummy<0> = 0) { return true; } + +template +typename disable_if, bool>::type +arithmetic_object(T t, dummy<1> = 0) { return false; } + + +int main() +{ + + BOOST_TEST(arithmetic_object(1)); + BOOST_TEST(arithmetic_object(1.0)); + + BOOST_TEST(!arithmetic_object("1")); + BOOST_TEST(!arithmetic_object(static_cast(0))); + + return boost::report_errors(); +} + diff --git a/test/eif_lazy.cpp b/test/eif_lazy.cpp new file mode 100644 index 0000000..029eca5 --- /dev/null +++ b/test/eif_lazy.cpp @@ -0,0 +1,81 @@ +// Boost enable_if library + +// Copyright 2003 (c) The Trustees of Indiana University. + +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include +#include +#include + +using boost::enable_if_c; +using boost::lazy_enable_if_c; + +// This class provides a reduced example of a traits class for +// computing the result of multiplying two types. The member typedef +// 'type' in this traits class defines the return type of this +// operator. The return type member is invalid unless both arguments +// for mult_traits are values that mult_traits expects (ints in this +// case). This kind of situation may arise if a traits class only +// makes sense for some set of types, not all C++ types. + +template struct is_int { + BOOST_STATIC_CONSTANT(bool, value = (boost::is_same::value)); +}; + +template +struct mult_traits { + typedef typename T::does_not_exist type; +}; + +template <> +struct mult_traits { + typedef int type; +}; + + +// Next, a forwarding function mult() is defined. It is enabled only +// when both arguments are of type int. The first version, using +// non-lazy enable_if_c does not work. + +#if 0 +template +typename enable_if_c< + is_int::value && is_int::value, + typename mult_traits::type +>::type +mult(const T& x, const U& y) {return x * y;} +#endif + +// A correct version uses lazy_enable_if_c. +// This template removes compiler errors from invalid code used as an +// argument to enable_if_c. + +#if 1 +template +typename lazy_enable_if_c< + is_int::value & is_int::value, + mult_traits +>::type +mult(const T& x, const U& y) {return x * y;} +#endif + +double mult(int i, double d) { return (double)i * d; } + +int main() +{ + + + BOOST_TEST(mult(1, 2) == 2); + + BOOST_TEST(mult(1, 3.0) == 3.0); + + return boost::report_errors(); +} + diff --git a/test/eif_lazy_test.cpp b/test/eif_lazy_test.cpp new file mode 100644 index 0000000..6077759 --- /dev/null +++ b/test/eif_lazy_test.cpp @@ -0,0 +1,98 @@ +// Boost enable_if library + +// Copyright 2003 (c) The Trustees of Indiana University. + +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +// Testing all variations of lazy_enable_if. + +#include +#include +#include + +using boost::lazy_enable_if; +using boost::lazy_disable_if; + +using boost::lazy_enable_if_c; +using boost::lazy_disable_if_c; + + +template +struct is_int_or_double { + BOOST_STATIC_CONSTANT(bool, + value = (boost::is_same::value || + boost::is_same::value)); +}; + +template +struct some_traits { + typedef typename T::does_not_exist type; +}; + +template <> +struct some_traits { + typedef bool type; +}; + +template <> +struct some_traits { + typedef bool type; +}; + +template +struct make_bool { + typedef bool type; +}; + +template <> +struct make_bool {}; + +template <> +struct make_bool {}; + +namespace A { + + template + typename lazy_enable_if, some_traits >::type + foo(T t) { return true; } + + template + typename lazy_enable_if_c::value, some_traits >::type + foo2(T t) { return true; } +} + +namespace B { + template + typename lazy_disable_if, make_bool >::type + foo(T t) { return false; } + + template + typename lazy_disable_if_c::value, make_bool >::type + foo2(T t) { return false; } +} + +int main() +{ + using namespace A; + using namespace B; + BOOST_TEST(foo(1)); + BOOST_TEST(foo(1.0)); + + BOOST_TEST(!foo("1")); + BOOST_TEST(!foo(static_cast(0))); + + BOOST_TEST(foo2(1)); + BOOST_TEST(foo2(1.0)); + + BOOST_TEST(!foo2("1")); + BOOST_TEST(!foo2(static_cast(0))); + + return boost::report_errors(); +} + diff --git a/test/eif_member_templates.cpp b/test/eif_member_templates.cpp new file mode 100644 index 0000000..2f1eeb2 --- /dev/null +++ b/test/eif_member_templates.cpp @@ -0,0 +1,42 @@ +// Boost enable_if library + +// Copyright 2003 (c) The Trustees of Indiana University. + +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include +#include +#include + +using boost::enable_if; +using boost::disable_if; +using boost::is_arithmetic; + +struct container { + template + typename enable_if, bool>::type + arithmetic_object(const T&, const int* /* disambiguate */ = 0) {return true;} + + template + typename disable_if, bool>::type + arithmetic_object(const T&) {return false;} +}; + +int main() +{ + + BOOST_TEST(container().arithmetic_object(1)); + BOOST_TEST(container().arithmetic_object(1.0)); + + BOOST_TEST(!container().arithmetic_object("1")); + BOOST_TEST(!container().arithmetic_object(static_cast(0))); + + return boost::report_errors(); +} + diff --git a/test/eif_namespace_disambiguation.cpp b/test/eif_namespace_disambiguation.cpp new file mode 100644 index 0000000..2a090cc --- /dev/null +++ b/test/eif_namespace_disambiguation.cpp @@ -0,0 +1,47 @@ +// Boost enable_if library + +// Copyright 2003 (c) The Trustees of Indiana University. + +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include + +#include +#include +#include + +using boost::enable_if; +using boost::mpl::not_; +using boost::is_arithmetic; + +namespace A { + template + typename enable_if, bool>::type + arithmetic_object(T t) { return true; } +} + +namespace B { + template + typename enable_if >, bool>::type + arithmetic_object(T t) { return false; } +} + +int main() +{ + using namespace A; + using namespace B; + BOOST_TEST(arithmetic_object(1)); + BOOST_TEST(arithmetic_object(1.0)); + + BOOST_TEST(!arithmetic_object("1")); + BOOST_TEST(!arithmetic_object(static_cast(0))); + + return boost::report_errors(); +} + diff --git a/test/eif_no_disambiguation.cpp b/test/eif_no_disambiguation.cpp new file mode 100644 index 0000000..d2ecbd9 --- /dev/null +++ b/test/eif_no_disambiguation.cpp @@ -0,0 +1,43 @@ +// Boost enable_if library + +// Copyright 2003 (c) The Trustees of Indiana University. + +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include + +#include +#include +#include + +using boost::mpl::not_; +using boost::enable_if; +using boost::is_arithmetic; + +template +typename enable_if, bool>::type +arithmetic_object(T t) { return true; } + +template +typename enable_if >, bool>::type +arithmetic_object(T t) { return false; } + + +int main() +{ + + BOOST_TEST(arithmetic_object(1)); + BOOST_TEST(arithmetic_object(1.0)); + + BOOST_TEST(!arithmetic_object("1")); + BOOST_TEST(!arithmetic_object(static_cast(0))); + + return boost::report_errors(); +} + diff --git a/test/eif_partial_specializations.cpp b/test/eif_partial_specializations.cpp new file mode 100644 index 0000000..a023f53 --- /dev/null +++ b/test/eif_partial_specializations.cpp @@ -0,0 +1,66 @@ +// Boost enable_if library + +// Copyright 2003 (c) The Trustees of Indiana University. + +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include +#include +#include + +using boost::enable_if_c; +using boost::disable_if_c; +using boost::enable_if; +using boost::disable_if; +using boost::is_arithmetic; + +template +struct tester; + +template +struct tester::value>::type> { + BOOST_STATIC_CONSTANT(bool, value = true); +}; + +template +struct tester::value>::type> { + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +template +struct tester2; + +template +struct tester2 >::type> { + BOOST_STATIC_CONSTANT(bool, value = true); +}; + +template +struct tester2 >::type> { + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +int main() +{ + + BOOST_TEST(tester::value); + BOOST_TEST(tester::value); + + BOOST_TEST(!tester::value); + BOOST_TEST(!tester::value); + + BOOST_TEST(tester2::value); + BOOST_TEST(tester2::value); + + BOOST_TEST(!tester2::value); + BOOST_TEST(!tester2::value); + + return boost::report_errors(); +} + diff --git a/test/ref_ct_test.cpp b/test/ref_ct_test.cpp new file mode 100644 index 0000000..34a79d2 --- /dev/null +++ b/test/ref_ct_test.cpp @@ -0,0 +1,121 @@ +// Copyright David Abrahams and Aleksey Gurtovoy +// 2002-2004. Distributed under the Boost Software License, Version +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// compile-time test for "boost/ref.hpp" header content +// see 'ref_test.cpp' for run-time part + +#include +#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; +} diff --git a/test/ref_test.cpp b/test/ref_test.cpp new file mode 100644 index 0000000..a8f5bd7 --- /dev/null +++ b/test/ref_test.cpp @@ -0,0 +1,101 @@ +// Copyright David Abrahams and Aleksey Gurtovoy +// 2002-2004. Distributed under the Boost Software License, Version +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// run-time test for "boost/ref.hpp" header content +// see 'ref_ct_test.cpp' for compile-time part + +#include +#include + +namespace { +using namespace boost; + +template +struct ref_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; + } + + template + static T* passthru(Arg x) + { + return get_pointer(x); + } + + template + static T const* cref_passthru(Arg x) + { + return get_const_pointer(x); + } + + static void test(T x) + { + BOOST_TEST(passthru(ref(x)) == &x); + BOOST_TEST(&ref(x).get() == &x); + + BOOST_TEST(cref_passthru(cref(x)) == &x); + BOOST_TEST(&cref(x).get() == &x); + } +}; + +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 +void do_unwrap(T t) { + + /* typename unwrap_reference::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_TEST(cc.count() == 0); + + do_unwrap(cc); + do_unwrap(ref(cc)); + do_unwrap(cref(cc)); + + BOOST_TEST(cc.count() == 1); + BOOST_TEST(unwrap_ref(ref(cc)).count() == 1); +} + +int main() +{ + ref_wrapper::test(1); + ref_wrapper::test(1); + unwrap_test(); + return boost::report_errors(); +}