From 806a96e42c03a0551bf2b5903d56efc468931711 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 22 Oct 2017 01:47:00 +0300 Subject: [PATCH] Add mp_nth_element_q --- doc/mp11/algorithm.adoc | 10 +++++- include/boost/mp11/algorithm.hpp | 1 + test/Jamfile | 1 + test/mp_nth_element_q.cpp | 59 ++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 test/mp_nth_element_q.cpp diff --git a/doc/mp11/algorithm.adoc b/doc/mp11/algorithm.adoc index 9ffe45c..fa0dc50 100644 --- a/doc/mp11/algorithm.adoc +++ b/doc/mp11/algorithm.adoc @@ -480,7 +480,8 @@ As `mp_sort`, but takes a quoted metafunction. ## mp_nth_element_c - template class P> using mp_nth_element_c = /*...*/; + template class P> using mp_nth_element_c = + /*...*/; Returns the element at position `I` in `mp_sort`. @@ -490,6 +491,13 @@ Returns the element at position `I` in `mp_sort`. Like `mp_nth_element_c`, but with a type argument `I`. `I::value` must be a nonnegative number. +## mp_nth_element_q + + template using mp_nth_element_q = + mp_nth_element; + +Like `mp_nth_element`, but takes a quoted metafunction. + ## mp_min_element template class P> using mp_min_element = /*...*/; diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index be94a83..08680b2 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -556,6 +556,7 @@ template class L, class T1, class... T, std::size_t I, templa template class P> using mp_nth_element_c = typename detail::mp_nth_element_impl::type; template class P> using mp_nth_element = typename detail::mp_nth_element_impl::type; +template using mp_nth_element_q = mp_nth_element; // mp_find namespace detail diff --git a/test/Jamfile b/test/Jamfile index eebca65..ba4a16d 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -87,6 +87,7 @@ run mp_from_sequence.cpp ; run mp_min_element.cpp ; run mp_max_element.cpp ; run mp_nth_element.cpp ; +run mp_nth_element_q.cpp ; # integral run integral.cpp ; diff --git a/test/mp_nth_element_q.cpp b/test/mp_nth_element_q.cpp new file mode 100644 index 0000000..0c6a333 --- /dev/null +++ b/test/mp_nth_element_q.cpp @@ -0,0 +1,59 @@ + +// Copyright 2017 Peter Dimov. +// +// Distributed under the Boost Software License, Version 1.0. +// +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + + +#include +#include +#include +#include +#include +#include +#include +#include + +int main() +{ + using boost::mp11::mp_nth_element_q; + using boost::mp11::mp_list_c; + using boost::mp11::mp_sort_q; + using boost::mp11::mp_less; + using boost::mp11::mp_at_c; + using boost::mp11::mp_size_t; + using boost::mp11::mp_rename; + using boost::mp11::mp_quote; + + using Q_less = mp_quote; + + { + using L1 = mp_list_c; + using L2 = mp_sort_q; + + BOOST_TEST_TRAIT_TRUE((std::is_same, Q_less>, mp_at_c>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, Q_less>, mp_at_c>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, Q_less>, mp_at_c>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, Q_less>, mp_at_c>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, Q_less>, mp_at_c>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, Q_less>, mp_at_c>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, Q_less>, mp_at_c>)); + } + + { + using L1 = mp_rename, std::tuple>; + using L2 = mp_sort_q; + + BOOST_TEST_TRAIT_TRUE((std::is_same, Q_less>, mp_at_c>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, Q_less>, mp_at_c>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, Q_less>, mp_at_c>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, Q_less>, mp_at_c>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, Q_less>, mp_at_c>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, Q_less>, mp_at_c>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, Q_less>, mp_at_c>)); + } + + return boost::report_errors(); +}