set_c.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/set_c.hpp>
  12. #include <boost/mpl/at.hpp>
  13. #include <boost/mpl/size.hpp>
  14. #include <boost/mpl/begin_end.hpp>
  15. #include <boost/mpl/aux_/test.hpp>
  16. namespace test { namespace {
  17. #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  18. template< typename S, typename S::value_type k >
  19. struct at_c
  20. : at< S, integral_c<typename S::value_type,k> >::type
  21. {
  22. };
  23. #else
  24. template< typename S, long k >
  25. struct at_c
  26. : aux::msvc_eti_base<
  27. at< S, integral_c<typename S::value_type,k> >
  28. >
  29. {
  30. };
  31. #endif
  32. }}
  33. #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
  34. MPL_TEST_CASE()
  35. {
  36. typedef set_c<bool,true>::type s1;
  37. typedef set_c<bool,false>::type s2;
  38. typedef set_c<bool,true,false>::type s3;
  39. MPL_ASSERT_RELATION( size<s1>::value, ==, 1 );
  40. MPL_ASSERT_RELATION( size<s2>::value, ==, 1 );
  41. MPL_ASSERT_RELATION( size<s3>::value, ==, 2 );
  42. MPL_ASSERT(( is_same< s1::value_type, bool > ));
  43. MPL_ASSERT(( is_same< s3::value_type, bool > ));
  44. MPL_ASSERT(( is_same< s2::value_type, bool > ));
  45. #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  46. MPL_ASSERT_RELATION( ( test::at_c<s1,true>::value ), ==, true );
  47. MPL_ASSERT_RELATION( ( test::at_c<s2,false>::value ), ==, false );
  48. MPL_ASSERT_RELATION( ( test::at_c<s3,true>::value ), ==, true );
  49. MPL_ASSERT_RELATION( ( test::at_c<s3,false>::value ), ==, false );
  50. MPL_ASSERT(( is_same< test::at_c<s1,false>::type, void_ > ));
  51. MPL_ASSERT(( is_same< test::at_c<s2,true>::type, void_ > ));
  52. #endif
  53. typedef begin<s1>::type first1;
  54. typedef end<s1>::type last1;
  55. MPL_ASSERT_RELATION( (distance<first1, last1>::value), ==, 1 );
  56. typedef begin<s2>::type first2;
  57. typedef end<s2>::type last2;
  58. MPL_ASSERT_RELATION( (distance<first2, last2>::value), ==, 1 );
  59. typedef begin<s3>::type first3;
  60. typedef end<s3>::type last3;
  61. MPL_ASSERT_RELATION( (distance<first3, last3>::value), ==, 2 );
  62. }
  63. #endif
  64. MPL_TEST_CASE()
  65. {
  66. typedef set_c<char,'a'>::type s1;
  67. typedef set_c<char,'a','b','c','d','e','f','g','h'>::type s2;
  68. MPL_ASSERT_RELATION( size<s1>::value, ==, 1 );
  69. MPL_ASSERT_RELATION( size<s2>::value, ==, 8 );
  70. MPL_ASSERT(( is_same< s1::value_type, char > ));
  71. MPL_ASSERT(( is_same< s2::value_type, char > ));
  72. #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  73. MPL_ASSERT_RELATION( ( test::at_c<s1,'a'>::value ), ==, 'a' );
  74. MPL_ASSERT_RELATION( ( test::at_c<s2,'a'>::value ), ==, 'a' );
  75. MPL_ASSERT_RELATION( ( test::at_c<s2,'d'>::value ), ==, 'd' );
  76. MPL_ASSERT_RELATION( ( test::at_c<s2,'h'>::value ), ==, 'h' );
  77. MPL_ASSERT(( is_same< test::at_c<s1,'z'>::type, void_ > ));
  78. MPL_ASSERT(( is_same< test::at_c<s2,'k'>::type, void_ > ));
  79. #endif
  80. typedef begin<s1>::type first1;
  81. typedef end<s1>::type last1;
  82. MPL_ASSERT_RELATION( (distance<first1, last1>::value), ==, 1 );
  83. typedef begin<s2>::type first2;
  84. typedef end<s2>::type last2;
  85. MPL_ASSERT_RELATION( (distance<first2, last2>::value), ==, 8 );
  86. }