Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/tr1/test/test_bind_tricky.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.6 KB
Line 
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
15template <class T>
16void check_placeholder(const T&)
17{
18   T t; 
19   T t2(t);
20   (void)t2;
21   BOOST_STATIC_ASSERT(::std::tr1::is_placeholder<T>::value);
22}
23
24template <class Binder, class R>
25void check_bind0(Binder b, R r)
26{
27   BOOST_STATIC_ASSERT(::std::tr1::is_bind_expression<Binder>::value);
28   verify_return_type(b(), r);
29
30   typedef typename Binder::result_type result_type;
31   BOOST_STATIC_ASSERT((::boost::is_same<result_type, R>::value));
32}
33
34template <class Binder, class R, class A1>
35void check_bind1(Binder b, R r, A1 a1)
36{
37   BOOST_STATIC_ASSERT(::std::tr1::is_bind_expression<Binder>::value);
38   verify_return_type(b(a1), r);
39}
40
41double test_proc(int a, char b, long c)
42{
43   return a+b+c;
44}
45
46struct from_double
47{
48   from_double(double){}
49};
50
51
52int main()
53{
54   check_placeholder(std::tr1::placeholders::_1);
55   check_placeholder(std::tr1::placeholders::_2);
56   check_placeholder(std::tr1::placeholders::_3);
57   check_placeholder(std::tr1::placeholders::_4);
58   check_placeholder(std::tr1::placeholders::_5);
59   check_placeholder(std::tr1::placeholders::_6);
60   check_placeholder(std::tr1::placeholders::_7);
61   check_placeholder(std::tr1::placeholders::_8);
62   check_placeholder(std::tr1::placeholders::_9);
63
64   check_bind0(std::tr1::bind(&test_proc, 0, 0, 0), double(0));
65   check_bind0(std::tr1::bind<double>(&test_proc, 0, 0, 0), double(0));
66   check_bind1(std::tr1::bind(&test_proc, 0, 0, std::tr1::placeholders::_1), double(0), 0);
67   check_bind1(std::tr1::bind(&test_proc, std::tr1::placeholders::_1, 0, 0), double(0), 0);
68
69   check_bind0(std::tr1::bind(test_proc, 0, 0, 0), double(0));
70   check_bind0(std::tr1::bind<double>(test_proc, 0, 0, 0), double(0));
71   check_bind1(std::tr1::bind(test_proc, 0, 0, std::tr1::placeholders::_1), double(0), 0);
72   check_bind1(std::tr1::bind(test_proc, std::tr1::placeholders::_1, 0, 0), double(0), 0);
73
74   check_bind0(std::tr1::bind(std::plus<double>(), 0, 1), double(0));
75   check_bind0(std::tr1::bind<double>(std::plus<double>(), 1, 0), double(0));
76   check_bind0(std::tr1::bind<from_double>(std::plus<double>(), 1, 0), from_double(0));
77   check_bind1(std::tr1::bind(std::plus<double>(), 0, std::tr1::placeholders::_1), double(0), 0);
78   check_bind1(std::tr1::bind(std::plus<double>(), std::tr1::placeholders::_1, 0), double(0), 0);
79   return 0;
80}
81
Note: See TracBrowser for help on using the repository browser.