| 1 | // Copyright David Abrahams and Aleksey Gurtovoy | 
|---|
| 2 | // 2002-2004. Distributed under the Boost Software License, Version | 
|---|
| 3 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at | 
|---|
| 4 | // http://www.boost.org/LICENSE_1_0.txt) | 
|---|
| 5 |  | 
|---|
| 6 | // run-time test for "boost/ref.hpp" header content | 
|---|
| 7 | // see 'ref_ct_test.cpp' for compile-time part | 
|---|
| 8 |  | 
|---|
| 9 | #if defined(_MSC_VER) && !defined(__ICL) | 
|---|
| 10 | # pragma warning(disable: 4786)  // identifier truncated in debug info | 
|---|
| 11 | # pragma warning(disable: 4710)  // function not inlined | 
|---|
| 12 | # pragma warning(disable: 4711)  // function selected for automatic inline expansion | 
|---|
| 13 | # pragma warning(disable: 4514)  // unreferenced inline removed | 
|---|
| 14 | #endif | 
|---|
| 15 |  | 
|---|
| 16 | #include <boost/ref.hpp> | 
|---|
| 17 |  | 
|---|
| 18 | #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) | 
|---|
| 19 | # pragma warning(push, 3) | 
|---|
| 20 | #endif | 
|---|
| 21 |  | 
|---|
| 22 | #include <iostream> | 
|---|
| 23 |  | 
|---|
| 24 | #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) | 
|---|
| 25 | # pragma warning(pop) | 
|---|
| 26 | #endif | 
|---|
| 27 |  | 
|---|
| 28 |  | 
|---|
| 29 | #define BOOST_INCLUDE_MAIN | 
|---|
| 30 | #include <boost/test/test_tools.hpp> | 
|---|
| 31 |  | 
|---|
| 32 | namespace { | 
|---|
| 33 | using namespace boost; | 
|---|
| 34 |  | 
|---|
| 35 | template <class T> | 
|---|
| 36 | struct ref_wrapper | 
|---|
| 37 | { | 
|---|
| 38 |     // Used to verify implicit conversion | 
|---|
| 39 |     static T* get_pointer(T& x) | 
|---|
| 40 |     { | 
|---|
| 41 |         return &x; | 
|---|
| 42 |     } | 
|---|
| 43 |  | 
|---|
| 44 |     static T const* get_const_pointer(T const& x) | 
|---|
| 45 |     { | 
|---|
| 46 |         return &x; | 
|---|
| 47 |     } | 
|---|
| 48 |  | 
|---|
| 49 |     template <class Arg> | 
|---|
| 50 |     static T* passthru(Arg x) | 
|---|
| 51 |     { | 
|---|
| 52 |         return get_pointer(x); | 
|---|
| 53 |     } | 
|---|
| 54 |  | 
|---|
| 55 |     template <class Arg> | 
|---|
| 56 |     static T const* cref_passthru(Arg x) | 
|---|
| 57 |     { | 
|---|
| 58 |         return get_const_pointer(x); | 
|---|
| 59 |     } | 
|---|
| 60 |  | 
|---|
| 61 |     static void test(T x) | 
|---|
| 62 |     { | 
|---|
| 63 |         BOOST_CHECK(passthru(ref(x)) == &x); | 
|---|
| 64 |         BOOST_CHECK(&ref(x).get() == &x); | 
|---|
| 65 |  | 
|---|
| 66 |         BOOST_CHECK(cref_passthru(cref(x)) == &x); | 
|---|
| 67 |         BOOST_CHECK(&cref(x).get() == &x); | 
|---|
| 68 |     } | 
|---|
| 69 | }; | 
|---|
| 70 |  | 
|---|
| 71 | } // namespace unnamed | 
|---|
| 72 |  | 
|---|
| 73 | int test_main(int, char * []) | 
|---|
| 74 | { | 
|---|
| 75 |     ref_wrapper<int>::test(1); | 
|---|
| 76 |     ref_wrapper<int const>::test(1); | 
|---|
| 77 |     return 0; | 
|---|
| 78 | } | 
|---|