Brian Silverman | 57be316 | 2018-08-04 23:36:33 -0700 | [diff] [blame^] | 1 | |
| 2 | // (C) Copyright Douglas Gregor 2003-2004. |
| 3 | // (C) Copyright Tobias Schwinger |
| 4 | // |
| 5 | // Use modification and distribution are subject to the boost Software License, |
| 6 | // Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt). |
| 7 | |
| 8 | //------------------------------------------------------------------------------ |
| 9 | // This file is a modified copy of the original Boost.ResultOf test-suite. |
| 10 | // See result_of.hpp in this directory for details. |
| 11 | |
| 12 | |
| 13 | #include "result_of.hpp" |
| 14 | |
| 15 | #include <utility> |
| 16 | #include <boost/static_assert.hpp> |
| 17 | #include <boost/type_traits/is_same.hpp> |
| 18 | |
| 19 | struct int_result_type { typedef int result_type; }; |
| 20 | |
| 21 | struct int_result_of |
| 22 | { |
| 23 | template<typename F> struct result { typedef int type; }; |
| 24 | }; |
| 25 | |
| 26 | struct int_result_type_and_float_result_of |
| 27 | { |
| 28 | typedef int result_type; |
| 29 | template<typename F> struct result { typedef float type; }; |
| 30 | }; |
| 31 | |
| 32 | struct X {}; |
| 33 | |
| 34 | int main() |
| 35 | { |
| 36 | using namespace boost; |
| 37 | namespace e = example; |
| 38 | |
| 39 | typedef int (*func_ptr)(float, double); |
| 40 | typedef int (&func_ref)(float, double); |
| 41 | typedef int (X::*mem_func_ptr)(float); |
| 42 | typedef int (X::*mem_func_ptr_c)(float) const; |
| 43 | typedef int (X::*mem_func_ptr_v)(float) volatile; |
| 44 | typedef int (X::*mem_func_ptr_cv)(float) const volatile; |
| 45 | |
| 46 | BOOST_STATIC_ASSERT((is_same<e::result_of<int_result_type(float)>::type, int>::value)); |
| 47 | BOOST_STATIC_ASSERT((is_same<e::result_of<int_result_of(double)>::type, int>::value)); |
| 48 | BOOST_STATIC_ASSERT((is_same<e::result_of<int_result_of(void)>::type, void>::value)); |
| 49 | BOOST_STATIC_ASSERT((is_same<e::result_of<const int_result_of(double)>::type, int>::value)); |
| 50 | BOOST_STATIC_ASSERT((is_same<e::result_of<volatile int_result_of(void)>::type, void>::value)); |
| 51 | BOOST_STATIC_ASSERT((is_same<e::result_of<int_result_type_and_float_result_of(char)>::type, int>::value)); |
| 52 | BOOST_STATIC_ASSERT((is_same<e::result_of<func_ptr(char, float)>::type, int>::value)); |
| 53 | BOOST_STATIC_ASSERT((is_same<e::result_of<func_ref(char, float)>::type, int>::value)); |
| 54 | BOOST_STATIC_ASSERT((is_same<e::result_of<mem_func_ptr(X,char)>::type, int>::value)); |
| 55 | BOOST_STATIC_ASSERT((is_same<e::result_of<mem_func_ptr_c(X,char)>::type, int>::value)); |
| 56 | BOOST_STATIC_ASSERT((is_same<e::result_of<mem_func_ptr_v(X,char)>::type, int>::value)); |
| 57 | BOOST_STATIC_ASSERT((is_same<e::result_of<mem_func_ptr_cv(X,char)>::type, int>::value)); |
| 58 | return 0; |
| 59 | } |