mp_replace_at.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2015, 2017 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. #if defined(_MSC_VER)
  8. #pragma warning( disable: 4804 ) // '>=': unsafe use of type 'bool' in operation
  9. #endif
  10. #include <boost/mp11/algorithm.hpp>
  11. #include <boost/mp11/list.hpp>
  12. #include <boost/mp11/integral.hpp>
  13. #include <boost/core/lightweight_test_trait.hpp>
  14. #include <type_traits>
  15. #include <tuple>
  16. #include <utility>
  17. struct X1 {};
  18. struct X2 {};
  19. struct X3 {};
  20. struct X4 {};
  21. struct X5 {};
  22. int main()
  23. {
  24. using boost::mp11::mp_list;
  25. using boost::mp11::mp_replace_at;
  26. using boost::mp11::mp_int;
  27. using boost::mp11::mp_true;
  28. using boost::mp11::mp_false;
  29. {
  30. using L = mp_list<X1, X2, X3, X4, X5>;
  31. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<0>, void>, mp_list<void, X2, X3, X4, X5>>));
  32. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<1>, void>, mp_list<X1, void, X3, X4, X5>>));
  33. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<2>, void>, mp_list<X1, X2, void, X4, X5>>));
  34. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<3>, void>, mp_list<X1, X2, X3, void, X5>>));
  35. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<4>, void>, mp_list<X1, X2, X3, X4, void>>));
  36. }
  37. {
  38. using L = std::tuple<X1, X2, X3, X4, X5>;
  39. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<0>, void>, std::tuple<void, X2, X3, X4, X5>>));
  40. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<1>, void>, std::tuple<X1, void, X3, X4, X5>>));
  41. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<2>, void>, std::tuple<X1, X2, void, X4, X5>>));
  42. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<3>, void>, std::tuple<X1, X2, X3, void, X5>>));
  43. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<4>, void>, std::tuple<X1, X2, X3, X4, void>>));
  44. }
  45. {
  46. using L = std::pair<X1, X2>;
  47. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_false, void>, std::pair<void, X2>>));
  48. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_true, void>, std::pair<X1, void>>));
  49. }
  50. return boost::report_errors();
  51. }