1 // (C) Copyright John Maddock 2005.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef BOOST_TR1_VERIFY_FUNCTOR_HPP
7 #define BOOST_TR1_VERIFY_FUNCTOR_HPP
9 #include <boost/type_traits/is_base_and_derived.hpp>
10 #include <boost/type_traits/is_same.hpp>
11 #include <boost/type_traits/remove_reference.hpp>
12 #include <boost/static_assert.hpp>
13 #include "verify_return.hpp"
15 template <class F, class R>
16 void verify_nullary_functor(F f, R)
18 verify_return_type(f(), R());
21 template <class F, class B>
22 void verify_unary_functor(F f, B)
24 #ifndef NO_INHERT_TEST
25 BOOST_STATIC_ASSERT( (::boost::is_base_and_derived<B, F>::value));
27 typedef typename B::argument_type arg_type;
28 typedef typename B::result_type result_type;
29 typedef typename F::argument_type b_arg_type;
30 typedef typename F::result_type b_result_type;
31 BOOST_STATIC_ASSERT((::boost::is_same<arg_type, b_arg_type>::value));
32 BOOST_STATIC_ASSERT((::boost::is_same<result_type, b_result_type>::value));
35 typedef typename boost::remove_reference<result_type>::type result_value;
36 verify_return_type(f(a), result_value());
39 template <class F, class B>
40 void verify_field_functor(F f, B)
42 // same as verify_unary_functor, but no nested result_type
43 // because it depends on the argument type.
44 typedef typename B::argument_type arg_type;
45 typedef typename B::result_type result_type;
48 typedef typename boost::remove_reference<result_type>::type result_value;
49 verify_return_type(f(a), result_value());
55 template <class F, class B>
56 void verify_binary_functor(F f, B)
58 #ifndef NO_INHERT_TEST
59 BOOST_STATIC_ASSERT( (::boost::is_base_and_derived<B, F>::value));
61 typedef typename B::first_argument_type b_arg1_type;
62 typedef typename B::second_argument_type b_arg2_type;
63 typedef typename B::result_type b_result_type;
64 typedef typename F::first_argument_type arg1_type;
65 typedef typename F::second_argument_type arg2_type;
66 typedef typename F::result_type result_type;
67 BOOST_STATIC_ASSERT((::boost::is_same<arg1_type, b_arg1_type>::value));
68 BOOST_STATIC_ASSERT((::boost::is_same<arg2_type, b_arg2_type>::value));
69 BOOST_STATIC_ASSERT((::boost::is_same<result_type, b_result_type>::value));
72 verify_return_type(f(a, b), result_type());