mp_replace.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/core/lightweight_test_trait.hpp>
  10. #include <type_traits>
  11. #include <tuple>
  12. #include <utility>
  13. struct X1 {};
  14. struct X2 {};
  15. struct X3 {};
  16. int main()
  17. {
  18. using boost::mp11::mp_list;
  19. using boost::mp11::mp_replace;
  20. {
  21. using L1 = mp_list<>;
  22. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L1, void, int[]>, L1>));
  23. using L2 = mp_list<X1, X2, X3, X2, X3, X3>;
  24. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, void, int[]>, L2>));
  25. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, X1, int[]>, mp_list<int[], X2, X3, X2, X3, X3>>));
  26. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, X2, int[]>, mp_list<X1, int[], X3, int[], X3, X3>>));
  27. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, X3, int[]>, mp_list<X1, X2, int[], X2, int[], int[]>>));
  28. }
  29. {
  30. using L1 = std::tuple<>;
  31. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L1, void, int[]>, L1>));
  32. using L2 = std::tuple<X1, X2, X3, X2, X3, X3>;
  33. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, void, int[]>, L2>));
  34. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, X1, int[]>, std::tuple<int[], X2, X3, X2, X3, X3>>));
  35. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, X2, int[]>, std::tuple<X1, int[], X3, int[], X3, X3>>));
  36. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, X3, int[]>, std::tuple<X1, X2, int[], X2, int[], int[]>>));
  37. }
  38. {
  39. using L2 = std::pair<X1, X2>;
  40. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, void, int[]>, L2>));
  41. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, X1, int[]>, std::pair<int[], X2>>));
  42. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, X2, int[]>, std::pair<X1, int[]>>));
  43. }
  44. return boost::report_errors();
  45. }