Blame view

3rdparty/boost_1_81_0/libs/mpl/test/bind.cpp 2.48 KB
73ef4ff3   Hu Chunming   提交三方库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  
  // Copyright Peter Dimov 2001-2002
  // Copyright Aleksey Gurtovoy 2001-2004
  //
  // Distributed under the Boost Software License,Version 1.0. 
  // (See accompanying file LICENSE_1_0.txt or copy at 
  // http://www.boost.org/LICENSE_1_0.txt)
  //
  // See http://www.boost.org/libs/mpl for documentation.
  
  // $Id$
  // $Date$
  // $Revision$
  
  #include <boost/mpl/bind.hpp>
  #include <boost/mpl/quote.hpp>
  #include <boost/mpl/if.hpp>
  #include <boost/mpl/next.hpp>
  #include <boost/mpl/bool.hpp>
  #include <boost/mpl/apply_wrap.hpp>
  #include <boost/mpl/aux_/test.hpp>
  
  #include <boost/type_traits/is_float.hpp>
  
  namespace {
  
  struct f1
  {
      template< typename T1 > struct apply
      {
          typedef T1 type;
      };
  };
  
  struct f5
  {
      template< typename T1, typename T2, typename T3, typename T4, typename T5 >
      struct apply
      {
          typedef T5 type;
      };
  };
  
  } // namespace
  
  MPL_TEST_CASE() // basic argument binding
  {
      typedef apply_wrap1< bind1<f1,_1>, int >::type r11;
      typedef apply_wrap5< bind1<f1,_5>, void,void,void,void,int >::type r12;
      MPL_ASSERT(( boost::is_same<r11,int> ));
      MPL_ASSERT(( boost::is_same<r12,int> ));
      
      typedef apply_wrap5< bind5<f5,_1,_2,_3,_4,_5>, void,void,void,void,int >::type r51;
      typedef apply_wrap5< bind5<f5,_5,_4,_3,_2,_1>, int,void,void,void,void >::type r52;
      MPL_ASSERT(( boost::is_same<r51,int> ));
      MPL_ASSERT(( boost::is_same<r52,int> ));
  }
  
  
  MPL_TEST_CASE() // fully bound metafunction classes
  {
      typedef apply_wrap0< bind1<f1,int> >::type r11;
      typedef apply_wrap0< bind5<f5,void,void,void,void,int> >::type r51;
      MPL_ASSERT(( boost::is_same<r11,int> ));
      MPL_ASSERT(( boost::is_same<r51,int> ));
  }
  
  
  MPL_TEST_CASE() // metafunction class composition
  {
      typedef apply_wrap5< bind5<f5,_1,_2,_3,_4,bind1<f1,_1> >, int,void,void,void,void >::type r51;
      typedef apply_wrap5< bind5<f5,_1,_2,_3,_4,bind1<f1,_5> >, void,void,void,void,int >::type r52;
      MPL_ASSERT(( boost::is_same<r51,int> ));
      MPL_ASSERT(( boost::is_same<r52,int> ));
  }
  
  #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
      && !defined(BOOST_MPL_CFG_NO_TEMPLATE_TEMPLATE_PARAMETERS) \
      && !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
  MPL_TEST_CASE() // if_ evaluation
  {
      typedef bind3< quote3<if_>, _1, bind1< quote1<next>, _2>, _3 > f;
      typedef apply_wrap3< f,true_,int_<0>,int >::type r1;
      typedef apply_wrap3< f,false_,int,int_<0> >::type r2;
      
      MPL_ASSERT(( boost::is_same<r1,int_<1> > ));
      MPL_ASSERT(( boost::is_same<r2,int_<0> > ));
  }
  #endif