mp_take.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright 2015 Peter Dimov.
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. //
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. #include <boost/mp11/algorithm.hpp>
  8. #include <boost/mp11/list.hpp>
  9. #include <boost/mp11/integral.hpp>
  10. #include <boost/core/lightweight_test_trait.hpp>
  11. #include <type_traits>
  12. #include <tuple>
  13. #include <utility>
  14. struct X1 {};
  15. struct X2 {};
  16. struct X3 {};
  17. struct X4 {};
  18. struct X5 {};
  19. int main()
  20. {
  21. using boost::mp11::mp_list;
  22. using boost::mp11::mp_take;
  23. using boost::mp11::mp_take_c;
  24. using boost::mp11::mp_size_t;
  25. {
  26. using L1 = mp_list<>;
  27. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L1, 0>, L1>));
  28. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L1, mp_size_t<0>>, L1>));
  29. using L2 = mp_list<X1, X2, X3, X4, X5>;
  30. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 0>, mp_list<>>));
  31. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 1>, mp_list<X1>>));
  32. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 2>, mp_list<X1, X2>>));
  33. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 3>, mp_list<X1, X2, X3>>));
  34. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 4>, mp_list<X1, X2, X3, X4>>));
  35. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 5>, mp_list<X1, X2, X3, X4, X5>>));
  36. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<0>>, mp_list<>>));
  37. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<1>>, mp_list<X1>>));
  38. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<2>>, mp_list<X1, X2>>));
  39. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<3>>, mp_list<X1, X2, X3>>));
  40. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<4>>, mp_list<X1, X2, X3, X4>>));
  41. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<5>>, mp_list<X1, X2, X3, X4, X5>>));
  42. using L3 = mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>;
  43. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L3, 6>, mp_list<X1, X2, X3, X4, X5, X1>>));
  44. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L3, 7>, mp_list<X1, X2, X3, X4, X5, X1, X2>>));
  45. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L3, 8>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3>>));
  46. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L3, 9>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4>>));
  47. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L3, 10>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>>));
  48. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L3, 11>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1>>));
  49. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L3, mp_size_t< 6>>, mp_list<X1, X2, X3, X4, X5, X1>>));
  50. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L3, mp_size_t< 7>>, mp_list<X1, X2, X3, X4, X5, X1, X2>>));
  51. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L3, mp_size_t< 8>>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3>>));
  52. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L3, mp_size_t< 9>>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4>>));
  53. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L3, mp_size_t<10>>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>>));
  54. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L3, mp_size_t<11>>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1>>));
  55. }
  56. {
  57. using L1 = std::tuple<>;
  58. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L1, 0>, L1>));
  59. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L1, mp_size_t<0>>, L1>));
  60. using L2 = std::tuple<X1, X2, X3, X4, X5>;
  61. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 0>, std::tuple<>>));
  62. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 1>, std::tuple<X1>>));
  63. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 2>, std::tuple<X1, X2>>));
  64. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 3>, std::tuple<X1, X2, X3>>));
  65. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 4>, std::tuple<X1, X2, X3, X4>>));
  66. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 5>, std::tuple<X1, X2, X3, X4, X5>>));
  67. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<0>>, std::tuple<>>));
  68. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<1>>, std::tuple<X1>>));
  69. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<2>>, std::tuple<X1, X2>>));
  70. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<3>>, std::tuple<X1, X2, X3>>));
  71. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<4>>, std::tuple<X1, X2, X3, X4>>));
  72. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<5>>, std::tuple<X1, X2, X3, X4, X5>>));
  73. using L3 = std::tuple<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>;
  74. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L3, 8>, std::tuple<X1, X2, X3, X4, X5, X1, X2, X3>>));
  75. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L3, mp_size_t<9>>, std::tuple<X1, X2, X3, X4, X5, X1, X2, X3, X4>>));
  76. }
  77. {
  78. using L1 = std::pair<X1, X2>;
  79. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L1, 2>, L1>));
  80. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L1, mp_size_t<2>>, L1>));
  81. }
  82. return boost::report_errors();
  83. }