mp_contains.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. int main()
  18. {
  19. using boost::mp11::mp_list;
  20. using boost::mp11::mp_contains;
  21. using boost::mp11::mp_true;
  22. using boost::mp11::mp_false;
  23. {
  24. using L1 = mp_list<>;
  25. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L1, void>, mp_false>));
  26. using L2 = mp_list<X1, X2, X3, X2, X3, X3>;
  27. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L2, void>, mp_false>));
  28. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L2, X1>, mp_true>));
  29. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L2, X2>, mp_true>));
  30. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L2, X3>, mp_true>));
  31. }
  32. {
  33. using L3 = std::tuple<>;
  34. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L3, void>, mp_false>));
  35. using L4 = std::tuple<X1, X2, X3, X2, X3, X3>;
  36. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L4, void>, mp_false>));
  37. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L4, X1>, mp_true>));
  38. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L4, X2>, mp_true>));
  39. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L4, X3>, mp_true>));
  40. }
  41. {
  42. using L5 = std::pair<X1, X2>;
  43. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L5, void>, mp_false>));
  44. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L5, X1>, mp_true>));
  45. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L5, X2>, mp_true>));
  46. }
  47. return boost::report_errors();
  48. }