mp_nth_element_q.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 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. #include <boost/mp11/algorithm.hpp>
  8. #include <boost/mp11/list.hpp>
  9. #include <boost/mp11/integral.hpp>
  10. #include <boost/mp11/function.hpp>
  11. #include <boost/mp11/utility.hpp>
  12. #include <boost/core/lightweight_test_trait.hpp>
  13. #include <type_traits>
  14. #include <tuple>
  15. int main()
  16. {
  17. using boost::mp11::mp_nth_element_q;
  18. using boost::mp11::mp_list_c;
  19. using boost::mp11::mp_sort_q;
  20. using boost::mp11::mp_less;
  21. using boost::mp11::mp_at_c;
  22. using boost::mp11::mp_size_t;
  23. using boost::mp11::mp_rename;
  24. using boost::mp11::mp_quote;
  25. using Q_less = mp_quote<mp_less>;
  26. {
  27. using L1 = mp_list_c<int, 7, 1, 11, 3, 2, 2, 4>;
  28. using L2 = mp_sort_q<L1, Q_less>;
  29. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_q<L1, mp_size_t<0>, Q_less>, mp_at_c<L2, 0>>));
  30. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_q<L1, mp_size_t<1>, Q_less>, mp_at_c<L2, 1>>));
  31. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_q<L1, mp_size_t<2>, Q_less>, mp_at_c<L2, 2>>));
  32. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_q<L1, mp_size_t<3>, Q_less>, mp_at_c<L2, 3>>));
  33. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_q<L1, mp_size_t<4>, Q_less>, mp_at_c<L2, 4>>));
  34. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_q<L1, mp_size_t<5>, Q_less>, mp_at_c<L2, 5>>));
  35. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_q<L1, mp_size_t<6>, Q_less>, mp_at_c<L2, 6>>));
  36. }
  37. {
  38. using L1 = mp_rename<mp_list_c<int, 7, 1, 11, 3, 2, 2, 4>, std::tuple>;
  39. using L2 = mp_sort_q<L1, Q_less>;
  40. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_q<L1, mp_size_t<0>, Q_less>, mp_at_c<L2, 0>>));
  41. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_q<L1, mp_size_t<1>, Q_less>, mp_at_c<L2, 1>>));
  42. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_q<L1, mp_size_t<2>, Q_less>, mp_at_c<L2, 2>>));
  43. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_q<L1, mp_size_t<3>, Q_less>, mp_at_c<L2, 3>>));
  44. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_q<L1, mp_size_t<4>, Q_less>, mp_at_c<L2, 4>>));
  45. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_q<L1, mp_size_t<5>, Q_less>, mp_at_c<L2, 5>>));
  46. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_q<L1, mp_size_t<6>, Q_less>, mp_at_c<L2, 6>>));
  47. }
  48. return boost::report_errors();
  49. }