mp_product.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 Y1 {};
  18. struct Z1 {};
  19. struct Z2 {};
  20. template<class T1, class T2, class T3> struct F {};
  21. template<class T> struct F1 {};
  22. int main()
  23. {
  24. using boost::mp11::mp_list;
  25. using boost::mp11::mp_product;
  26. using boost::mp11::mp_product_q;
  27. using boost::mp11::mp_quote;
  28. {
  29. using L1 = std::tuple<X1, X2, X3>;
  30. using L2 = mp_list<Y1>;
  31. using L3 = std::pair<Z1, Z2>;
  32. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_product<F, L1, L2, L3>, std::tuple<F<X1, Y1, Z1>, F<X1, Y1, Z2>, F<X2, Y1, Z1>, F<X2, Y1, Z2>, F<X3, Y1, Z1>, F<X3, Y1, Z2>>>));
  33. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_product_q<mp_quote<F>, L1, L2, L3>, std::tuple<F<X1, Y1, Z1>, F<X1, Y1, Z2>, F<X2, Y1, Z1>, F<X2, Y1, Z2>, F<X3, Y1, Z1>, F<X3, Y1, Z2>>>));
  34. }
  35. {
  36. using L1 = std::tuple<X1, X2, X3>;
  37. using L2 = mp_list<>;
  38. using L3 = std::pair<Z1, Z2>;
  39. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_product<F, L1, L2, L3>, std::tuple<>>));
  40. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_product_q<mp_quote<F>, L1, L2, L3>, std::tuple<>>));
  41. }
  42. {
  43. using L1 = std::tuple<X1, X2, X3>;
  44. using L2 = mp_list<X1, X2, X3>;
  45. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_product<F1, L1>, std::tuple<F1<X1>, F1<X2>, F1<X3>>>));
  46. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_product_q<mp_quote<F1>, L1>, std::tuple<F1<X1>, F1<X2>, F1<X3>>>));
  47. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_product<F1, L2>, mp_list<F1<X1>, F1<X2>, F1<X3>>>));
  48. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_product_q<mp_quote<F1>, L2>, mp_list<F1<X1>, F1<X2>, F1<X3>>>));
  49. }
  50. return boost::report_errors();
  51. }