bind.cpp 2.5 KB

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