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)
5 
6 #ifdef TEST_STD_HEADERS
7 #include <functional>
8 #else
9 #include <boost/tr1/functional.hpp>
10 #endif
11 
12 #include <boost/static_assert.hpp>
13 #include "verify_return.hpp"
14 
15 // This should verify that _1 etc are lvalues, but we leave that
16 // to the "tricky" test as the Boost implementation doesn't always
17 // guarentee that:
18 template <class T>
check_placeholder(T)19 void check_placeholder(T)
20 {
21    T t;
22    T t2(t);
23    (void)t2;
24    //BOOST_STATIC_ASSERT(::std::tr1::is_placeholder<T>::value);
25 }
26 
27 template <class Binder, class R>
check_bind0(Binder b,R r)28 void check_bind0(Binder b, R r)
29 {
30    //BOOST_STATIC_ASSERT(::std::tr1::is_bind_expression<Binder>::value);
31    verify_return_type(b(), r);
32 
33    typedef typename Binder::result_type result_type;
34    BOOST_STATIC_ASSERT((::boost::is_same<result_type, R>::value));
35 }
36 
37 template <class Binder, class R, class A1>
check_bind1(Binder b,R r,A1 a1)38 void check_bind1(Binder b, R r, A1 a1)
39 {
40    //BOOST_STATIC_ASSERT(::std::tr1::is_bind_expression<Binder>::value);
41    verify_return_type(b(a1), r);
42 }
43 
test_proc(int a,char b,long c)44 double test_proc(int a, char b, long c)
45 {
46    return a+b+c;
47 }
48 
49 struct from_double
50 {
from_doublefrom_double51    from_double(double){}
52 };
53 
54 
main()55 int main()
56 {
57    check_placeholder(std::tr1::placeholders::_1);
58    check_placeholder(std::tr1::placeholders::_2);
59    check_placeholder(std::tr1::placeholders::_3);
60    check_placeholder(std::tr1::placeholders::_4);
61    check_placeholder(std::tr1::placeholders::_5);
62    check_placeholder(std::tr1::placeholders::_6);
63    check_placeholder(std::tr1::placeholders::_7);
64    check_placeholder(std::tr1::placeholders::_8);
65    check_placeholder(std::tr1::placeholders::_9);
66 
67    check_bind0(std::tr1::bind(&test_proc, 0, 0, 0), double(0));
68    //check_bind0(std::tr1::bind<double>(&test_proc, 0, 0, 0), double(0));
69    check_bind1(std::tr1::bind(&test_proc, 0, 0, std::tr1::placeholders::_1), double(0), 0);
70    check_bind1(std::tr1::bind(&test_proc, std::tr1::placeholders::_1, 0, 0), double(0), 0);
71 
72    check_bind0(std::tr1::bind(test_proc, 0, 0, 0), double(0));
73    //check_bind0(std::tr1::bind<double>(test_proc, 0, 0, 0), double(0));
74    check_bind1(std::tr1::bind(test_proc, 0, 0, std::tr1::placeholders::_1), double(0), 0);
75    check_bind1(std::tr1::bind(test_proc, std::tr1::placeholders::_1, 0, 0), double(0), 0);
76 
77    check_bind0(std::tr1::bind(std::plus<double>(), 0, 1), double(0));
78    check_bind0(std::tr1::bind<double>(std::plus<double>(), 1, 0), double(0));
79    check_bind0(std::tr1::bind<from_double>(std::plus<double>(), 1, 0), from_double(0));
80    check_bind1(std::tr1::bind(std::plus<double>(), 0, std::tr1::placeholders::_1), double(0), 0);
81    check_bind1(std::tr1::bind(std::plus<double>(), std::tr1::placeholders::_1, 0), double(0), 0);
82    return 0;
83 }
84 
85