|
|
View of /trunk/pstade/libs/egg/test/return_of.cpp
Revision 1824 -
(download)
Thu Jan 31 18:25:19 2008 UTC (8 months, 1 week ago) by mb2sync File size: 2332 byte(s) hmm, maybe unneeded. 1 #include <pstade/vodka/drink.hpp> 2 3 4 // PStade.Wine 5 // 6 // Copyright Shunsuke Sogame 2005-2006. 7 // Distributed under the Boost Software License, Version 1.0. 8 // (See accompanying file LICENSE_1_0.txt or copy at 9 // http://www.boost.org/LICENSE_1_0.txt) 10 11 12 #include <pstade/egg/return_of.hpp> 13 #include <pstade/lightweight_test.hpp> 14 15 16 #include <boost/mpl/assert.hpp> 17 #include <boost/type_traits/is_same.hpp> 18 #include <pstade/egg/apply.hpp> 19 20 21 using pstade::egg::return_of; 22 using pstade::egg::as_arg; 23 using pstade::egg::T_apply; 24 using pstade::egg::apply; 25 26 27 struct T_plus 28 { 29 typedef int result_type; 30 31 result_type operator()(int i, int j) const 32 { 33 return i + j; 34 } 35 }; 36 37 T_plus const plus = {}; 38 39 struct T_negate 40 { 41 typedef int result_type; 42 43 result_type operator()(int i) const 44 { 45 return -i; 46 } 47 }; 48 49 T_negate const negate = {}; 50 51 52 int minus(int i, int j) 53 { 54 return i - j; 55 } 56 57 58 BOOST_MPL_ASSERT((boost::is_same<return_of<T_plus(int, int)>::type, int>)); 59 BOOST_MPL_ASSERT((boost::is_same<return_of<T_plus(int, T_plus(int, int))>::type, int>)); 60 BOOST_MPL_ASSERT((boost::is_same<return_of<T_plus(T_plus(int, int), int)>::type, int>)); 61 BOOST_MPL_ASSERT((boost::is_same<return_of<T_plus(T_plus(int, as_arg<int>), T_plus(int, int))>::type, int>)); 62 BOOST_MPL_ASSERT((boost::is_same<return_of<T_plus(T_plus(int, int), T_plus(int, T_plus(int, as_arg<int>)))>::type, int>)); 63 64 BOOST_MPL_ASSERT((boost::is_same<return_of<T_negate(int)>::type, int>)); 65 BOOST_MPL_ASSERT((boost::is_same<return_of<T_plus(T_negate(int), T_plus(int, int))>::type, int>)); 66 BOOST_MPL_ASSERT((boost::is_same<return_of<T_plus(T_plus(int, int), T_negate(int))>::type, int>)); 67 68 BOOST_MPL_ASSERT((boost::is_same<return_of<T_apply(as_arg<int(*)(int, int)>, int)>::type, int>)); 69 70 71 void pstade_lightweight_test() 72 { 73 { 74 return_of<T_plus(T_plus(int, int), int)>::type 75 r = plus(plus(1, 2), 3); 76 BOOST_CHECK( r == 1+2+3 ); 77 } 78 { 79 return_of<T_plus(T_plus(int, T_negate(int)), int)>::type 80 r = plus(plus(1, negate(2)), 3); 81 BOOST_CHECK( r == 1+(-2)+3 ); 82 } 83 { 84 return_of<T_apply(as_arg<int(*)(int, int)>, int)>::type 85 r = apply(&minus, 3, 2); 86 BOOST_CHECK( r == 1 ); 87 } 88 } |
| Powered by ViewVC 1.0.5 | ViewVC Help |