| 1 | // Boost result_of library |
|---|
| 2 | |
|---|
| 3 | // Copyright Douglas Gregor 2003-2004. Use, modification and |
|---|
| 4 | // distribution is subject to the Boost Software License, Version |
|---|
| 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 6 | // http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 7 | |
|---|
| 8 | // For more information, see http://www.boost.org/libs/utility |
|---|
| 9 | #include <boost/utility/result_of.hpp> |
|---|
| 10 | #include <utility> |
|---|
| 11 | #include <boost/static_assert.hpp> |
|---|
| 12 | #include <boost/type_traits/is_same.hpp> |
|---|
| 13 | |
|---|
| 14 | struct int_result_type { typedef int result_type; }; |
|---|
| 15 | |
|---|
| 16 | struct int_result_of |
|---|
| 17 | { |
|---|
| 18 | template<typename F> struct result { typedef int type; }; |
|---|
| 19 | }; |
|---|
| 20 | |
|---|
| 21 | struct int_result_type_and_float_result_of |
|---|
| 22 | { |
|---|
| 23 | typedef int result_type; |
|---|
| 24 | template<typename F> struct result { typedef float type; }; |
|---|
| 25 | }; |
|---|
| 26 | |
|---|
| 27 | struct X {}; |
|---|
| 28 | |
|---|
| 29 | int main() |
|---|
| 30 | { |
|---|
| 31 | using namespace boost; |
|---|
| 32 | |
|---|
| 33 | typedef int (*func_ptr)(float, double); |
|---|
| 34 | typedef int (&func_ref)(float, double); |
|---|
| 35 | typedef int (X::*mem_func_ptr)(float); |
|---|
| 36 | typedef int (X::*mem_func_ptr_c)(float) const; |
|---|
| 37 | typedef int (X::*mem_func_ptr_v)(float) volatile; |
|---|
| 38 | typedef int (X::*mem_func_ptr_cv)(float) const volatile; |
|---|
| 39 | |
|---|
| 40 | BOOST_STATIC_ASSERT((is_same<result_of<int_result_type(float)>::type, int>::value)); |
|---|
| 41 | BOOST_STATIC_ASSERT((is_same<result_of<int_result_of(double)>::type, int>::value)); |
|---|
| 42 | BOOST_STATIC_ASSERT((is_same<result_of<int_result_of(void)>::type, void>::value)); |
|---|
| 43 | BOOST_STATIC_ASSERT((is_same<result_of<const int_result_of(double)>::type, int>::value)); |
|---|
| 44 | BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of(void)>::type, void>::value)); |
|---|
| 45 | BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_and_float_result_of(char)>::type, int>::value)); |
|---|
| 46 | BOOST_STATIC_ASSERT((is_same<result_of<func_ptr(char, float)>::type, int>::value)); |
|---|
| 47 | BOOST_STATIC_ASSERT((is_same<result_of<func_ref(char, float)>::type, int>::value)); |
|---|
| 48 | BOOST_STATIC_ASSERT((is_same<result_of<mem_func_ptr(X,char)>::type, int>::value)); |
|---|
| 49 | BOOST_STATIC_ASSERT((is_same<result_of<mem_func_ptr_c(X,char)>::type, int>::value)); |
|---|
| 50 | BOOST_STATIC_ASSERT((is_same<result_of<mem_func_ptr_v(X,char)>::type, int>::value)); |
|---|
| 51 | BOOST_STATIC_ASSERT((is_same<result_of<mem_func_ptr_cv(X,char)>::type, int>::value)); |
|---|
| 52 | return 0; |
|---|
| 53 | } |
|---|