mp_transform_q.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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/utility.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 Y1 {};
  19. struct Y2 {};
  20. struct Y3 {};
  21. struct Y4 {};
  22. struct Z1 {};
  23. struct Z2 {};
  24. struct Z3 {};
  25. struct Z4 {};
  26. struct U1 {};
  27. struct U2 {};
  28. struct V1 {};
  29. struct V2 {};
  30. struct W1 {};
  31. struct W2 {};
  32. using boost::mp11::mp_quote;
  33. using boost::mp11::mp_list;
  34. template<class T> using add_pointer = typename std::add_pointer<T>::type;
  35. using Q_add_pointer = mp_quote<add_pointer>;
  36. template<class T, class U> using is_same = typename std::is_same<T, U>::type;
  37. using Q_is_same = mp_quote<is_same>;
  38. using Q_mp_list = mp_quote<mp_list>;
  39. using Q_std_tuple = mp_quote<std::tuple>;
  40. using Q_std_pair = mp_quote<std::pair>;
  41. int main()
  42. {
  43. using boost::mp11::mp_transform_q;
  44. using L1 = mp_list<X1, X2, X3, X4>;
  45. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_mp_list, L1>, mp_list<mp_list<X1>, mp_list<X2>, mp_list<X3>, mp_list<X4>>>));
  46. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_std_tuple, L1>, mp_list<std::tuple<X1>, std::tuple<X2>, std::tuple<X3>, std::tuple<X4>>>));
  47. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_add_pointer, L1>, mp_list<X1*, X2*, X3*, X4*>>));
  48. using L2 = std::tuple<Y1, Y2, Y3, Y4>;
  49. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_mp_list, L1, L2>, mp_list<mp_list<X1, Y1>, mp_list<X2, Y2>, mp_list<X3, Y3>, mp_list<X4, Y4>>>));
  50. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_std_tuple, L1, L2>, mp_list<std::tuple<X1, Y1>, std::tuple<X2, Y2>, std::tuple<X3, Y3>, std::tuple<X4, Y4>>>));
  51. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_std_pair, L1, L2>, mp_list<std::pair<X1, Y1>, std::pair<X2, Y2>, std::pair<X3, Y3>, std::pair<X4, Y4>>>));
  52. using L3 = mp_list<Z1, Z2, Z3, Z4>;
  53. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_mp_list, L1, L2, L3>, mp_list<mp_list<X1, Y1, Z1>, mp_list<X2, Y2, Z2>, mp_list<X3, Y3, Z3>, mp_list<X4, Y4, Z4>>>));
  54. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_std_tuple, L1, L2, L3>, mp_list<std::tuple<X1, Y1, Z1>, std::tuple<X2, Y2, Z2>, std::tuple<X3, Y3, Z3>, std::tuple<X4, Y4, Z4>>>));
  55. //
  56. using L4 = std::tuple<X1, Y2, X3, Y4>;
  57. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_is_same, L1, L1>, mp_list<std::true_type, std::true_type, std::true_type, std::true_type>>));
  58. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_is_same, L1, L2>, mp_list<std::false_type, std::false_type, std::false_type, std::false_type>>));
  59. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_is_same, L1, L4>, mp_list<std::true_type, std::false_type, std::true_type, std::false_type>>));
  60. //
  61. using L5 = std::pair<X1, X2>;
  62. using L6 = std::pair<Y1, Y2>;
  63. using L7 = std::pair<X1, Y2>;
  64. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_mp_list, L5>, std::pair<mp_list<X1>, mp_list<X2>>>));
  65. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_mp_list, L5, L6>, std::pair<mp_list<X1, Y1>, mp_list<X2, Y2>>>));
  66. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_mp_list, L5, L6, L7>, std::pair<mp_list<X1, Y1, X1>, mp_list<X2, Y2, Y2>>>));
  67. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_add_pointer, L5>, std::pair<X1*, X2*>>));
  68. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_is_same, L5, L5>, std::pair<std::true_type, std::true_type>>));
  69. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_is_same, L5, L6>, std::pair<std::false_type, std::false_type>>));
  70. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_is_same, L5, L7>, std::pair<std::true_type, std::false_type>>));
  71. //
  72. using L8 = std::pair<Z1, Z2>;
  73. using L9 = std::pair<U1, U2>;
  74. using L10 = std::pair<V1, V2>;
  75. using L11 = std::pair<W1, W2>;
  76. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_std_tuple, L5, L6, L8, L9>, std::pair<std::tuple<X1, Y1, Z1, U1>, std::tuple<X2, Y2, Z2, U2>>>));
  77. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_std_tuple, L5, L6, L8, L9, L10>, std::pair<std::tuple<X1, Y1, Z1, U1, V1>, std::tuple<X2, Y2, Z2, U2, V2>>>));
  78. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_std_tuple, L5, L6, L8, L9, L10, L11>, std::pair<std::tuple<X1, Y1, Z1, U1, V1, W1>, std::tuple<X2, Y2, Z2, U2, V2, W2>>>));
  79. //
  80. return boost::report_errors();
  81. }