diff --git a/doc/mp11/algorithm.adoc b/doc/mp11/algorithm.adoc index fa0dc50..5c6b22a 100644 --- a/doc/mp11/algorithm.adoc +++ b/doc/mp11/algorithm.adoc @@ -504,7 +504,13 @@ Like `mp_nth_element`, but takes a quoted metafunction. `mp_min_element` returns the minimal element of the list `L` according to the ordering `mp_to_bool>`. -It's equivalent to `mp_fold, mp_first, Q>`, where `Q` returns `mp_if, T, U>`. +It's equivalent to `mp_fold, mp_first, F>`, where `F` returns `mp_if, T, U>`. + +## mp_min_element_q + + template using mp_min_element_q = mp_min_element; + +As `mp_min_element`, but takes a quoted metafunction. ## mp_max_element @@ -512,7 +518,13 @@ It's equivalent to `mp_fold, mp_first, Q>`, where `Q` return `mp_max_element` returns the maximal element of the list `L` according to the ordering `mp_to_bool>`. -It's equivalent to `mp_fold, mp_first, Q>`, where `Q` returns `mp_if, T, U>`. +It's equivalent to `mp_fold, mp_first, F>`, where `F` returns `mp_if, T, U>`. + +## mp_max_element_q + + template using mp_max_element_q = mp_max_element; + +As `mp_max_element`, but takes a quoted metafunction. ## mp_find diff --git a/include/boost/mp11/detail/mp_min_element.hpp b/include/boost/mp11/detail/mp_min_element.hpp index 3b4f274..55c21ac 100644 --- a/include/boost/mp11/detail/mp_min_element.hpp +++ b/include/boost/mp11/detail/mp_min_element.hpp @@ -29,6 +29,7 @@ template class P> struct select_min } // namespace detail template class P> using mp_min_element = mp_fold_q, mp_first, detail::select_min

>; +template using mp_min_element_q = mp_min_element; // mp_max_element namespace detail @@ -42,6 +43,7 @@ template class P> struct select_max } // namespace detail template class P> using mp_max_element = mp_fold_q, mp_first, detail::select_max

>; +template using mp_max_element_q = mp_max_element; } // namespace mp11 } // namespace boost diff --git a/test/Jamfile b/test/Jamfile index ba4a16d..ed2e96c 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -85,7 +85,9 @@ run mp_with_index.cpp ; run mp_with_index_cx.cpp ; run mp_from_sequence.cpp ; run mp_min_element.cpp ; +run mp_min_element_q.cpp ; run mp_max_element.cpp ; +run mp_max_element_q.cpp ; run mp_nth_element.cpp ; run mp_nth_element_q.cpp ; diff --git a/test/mp_max_element_q.cpp b/test/mp_max_element_q.cpp new file mode 100644 index 0000000..36a79c4 --- /dev/null +++ b/test/mp_max_element_q.cpp @@ -0,0 +1,58 @@ + +// 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 + +using boost::mp11::mp_bool; + +struct Q_sizeof_less +{ + template using fn = mp_bool<(sizeof(T) < sizeof(U))>; +}; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_max_element_q; + + { + using L1 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, void>)); + + using L2 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, char[4]>)); + + using L3 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, char[4]>)); + } + + { + using L1 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, void>)); + + using L2 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, char[4]>)); + + using L3 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, char[4]>)); + } + + return boost::report_errors(); +} diff --git a/test/mp_min_element_q.cpp b/test/mp_min_element_q.cpp new file mode 100644 index 0000000..b1a0920 --- /dev/null +++ b/test/mp_min_element_q.cpp @@ -0,0 +1,58 @@ + +// 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 + +using boost::mp11::mp_bool; + +struct Q_sizeof_less +{ + template using fn = mp_bool<(sizeof(T) < sizeof(U))>; +}; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_min_element_q; + + { + using L1 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, void>)); + + using L2 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, char[1]>)); + + using L3 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, char[1]>)); + } + + { + using L1 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, void>)); + + using L2 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, char[1]>)); + + using L3 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, char[1]>)); + } + + return boost::report_errors(); +}