list_c.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright Aleksey Gurtovoy 2000-2004
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/mpl for documentation.
  8. // $Id$
  9. // $Date$
  10. // $Revision$
  11. #include <boost/mpl/list_c.hpp>
  12. #include <boost/mpl/front.hpp>
  13. #include <boost/mpl/size.hpp>
  14. #include <boost/static_assert.hpp>
  15. #include <boost/mpl/aux_/test.hpp>
  16. #if !BOOST_WORKAROUND(BOOST_MSVC,<= 1200)
  17. MPL_TEST_CASE()
  18. {
  19. typedef list_c<bool,true>::type l1;
  20. typedef list_c<bool,false>::type l2;
  21. MPL_ASSERT(( is_same< l1::value_type, bool > ));
  22. MPL_ASSERT(( is_same< l2::value_type, bool > ));
  23. MPL_ASSERT_RELATION( front<l1>::type::value, ==, true );
  24. MPL_ASSERT_RELATION( front<l2>::type::value, ==, false );
  25. }
  26. #endif
  27. MPL_TEST_CASE()
  28. {
  29. typedef list_c<int,-1>::type l1;
  30. typedef list_c<int,0,1>::type l2;
  31. typedef list_c<int,1,2,3>::type l3;
  32. MPL_ASSERT(( is_same< l1::value_type, int > ));
  33. MPL_ASSERT(( is_same< l2::value_type, int > ));
  34. MPL_ASSERT(( is_same< l3::value_type, int > ));
  35. MPL_ASSERT_RELATION( size<l1>::value, ==, 1 );
  36. MPL_ASSERT_RELATION( size<l2>::value, ==, 2 );
  37. MPL_ASSERT_RELATION( size<l3>::value, ==, 3 );
  38. MPL_ASSERT_RELATION( front<l1>::type::value, ==, -1 );
  39. MPL_ASSERT_RELATION( front<l2>::type::value, ==, 0 );
  40. MPL_ASSERT_RELATION( front<l3>::type::value, ==, 1 );
  41. }
  42. MPL_TEST_CASE()
  43. {
  44. typedef list_c<unsigned,0>::type l1;
  45. typedef list_c<unsigned,1,2>::type l2;
  46. MPL_ASSERT(( is_same< l1::value_type, unsigned > ));
  47. MPL_ASSERT(( is_same< l2::value_type, unsigned > ));
  48. MPL_ASSERT_RELATION( size<l1>::value, ==, 1 );
  49. MPL_ASSERT_RELATION( size<l2>::value, ==, 2 );
  50. MPL_ASSERT_RELATION( front<l1>::type::value, ==, 0 );
  51. MPL_ASSERT_RELATION( front<l2>::type::value, ==, 1 );
  52. }
  53. MPL_TEST_CASE()
  54. {
  55. typedef list_c<unsigned,2,1> l2;
  56. MPL_ASSERT(( is_same< l2::value_type, unsigned > ));
  57. typedef begin<l2>::type i1;
  58. typedef next<i1>::type i2;
  59. typedef next<i2>::type i3;
  60. MPL_ASSERT_RELATION( deref<i1>::type::value, ==, 2 );
  61. MPL_ASSERT_RELATION( deref<i2>::type::value, ==, 1 );
  62. MPL_ASSERT(( is_same< i3, end<l2>::type > ));
  63. }