mp_nth_element.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/core/lightweight_test_trait.hpp>
  12. #include <type_traits>
  13. #include <tuple>
  14. int main()
  15. {
  16. using boost::mp11::mp_nth_element;
  17. using boost::mp11::mp_nth_element_c;
  18. using boost::mp11::mp_list_c;
  19. using boost::mp11::mp_sort;
  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. {
  25. using L1 = mp_list_c<int, 7, 1, 11, 3, 2, 2, 4>;
  26. using L2 = mp_sort<L1, mp_less>;
  27. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_c<L1, 0, mp_less>, mp_at_c<L2, 0>>));
  28. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_c<L1, 1, mp_less>, mp_at_c<L2, 1>>));
  29. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_c<L1, 2, mp_less>, mp_at_c<L2, 2>>));
  30. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_c<L1, 3, mp_less>, mp_at_c<L2, 3>>));
  31. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_c<L1, 4, mp_less>, mp_at_c<L2, 4>>));
  32. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_c<L1, 5, mp_less>, mp_at_c<L2, 5>>));
  33. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_c<L1, 6, mp_less>, mp_at_c<L2, 6>>));
  34. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element<L1, mp_size_t<0>, mp_less>, mp_at_c<L2, 0>>));
  35. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element<L1, mp_size_t<1>, mp_less>, mp_at_c<L2, 1>>));
  36. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element<L1, mp_size_t<2>, mp_less>, mp_at_c<L2, 2>>));
  37. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element<L1, mp_size_t<3>, mp_less>, mp_at_c<L2, 3>>));
  38. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element<L1, mp_size_t<4>, mp_less>, mp_at_c<L2, 4>>));
  39. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element<L1, mp_size_t<5>, mp_less>, mp_at_c<L2, 5>>));
  40. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element<L1, mp_size_t<6>, mp_less>, mp_at_c<L2, 6>>));
  41. }
  42. {
  43. using L1 = mp_rename<mp_list_c<int, 7, 1, 11, 3, 2, 2, 4>, std::tuple>;
  44. using L2 = mp_sort<L1, mp_less>;
  45. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_c<L1, 0, mp_less>, mp_at_c<L2, 0>>));
  46. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_c<L1, 1, mp_less>, mp_at_c<L2, 1>>));
  47. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_c<L1, 2, mp_less>, mp_at_c<L2, 2>>));
  48. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_c<L1, 3, mp_less>, mp_at_c<L2, 3>>));
  49. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_c<L1, 4, mp_less>, mp_at_c<L2, 4>>));
  50. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_c<L1, 5, mp_less>, mp_at_c<L2, 5>>));
  51. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element_c<L1, 6, mp_less>, mp_at_c<L2, 6>>));
  52. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element<L1, mp_size_t<0>, mp_less>, mp_at_c<L2, 0>>));
  53. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element<L1, mp_size_t<1>, mp_less>, mp_at_c<L2, 1>>));
  54. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element<L1, mp_size_t<2>, mp_less>, mp_at_c<L2, 2>>));
  55. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element<L1, mp_size_t<3>, mp_less>, mp_at_c<L2, 3>>));
  56. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element<L1, mp_size_t<4>, mp_less>, mp_at_c<L2, 4>>));
  57. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element<L1, mp_size_t<5>, mp_less>, mp_at_c<L2, 5>>));
  58. BOOST_TEST_TRAIT_TRUE((std::is_same<mp_nth_element<L1, mp_size_t<6>, mp_less>, mp_at_c<L2, 6>>));
  59. }
  60. return boost::report_errors();
  61. }