From c9d1562cee470e6121c5642f7ba7661b0088600d Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 15 Jul 2015 18:11:16 +0300 Subject: [PATCH] Add mp_find, mp_find_if. --- include/boost/mp11/algorithm.hpp | 3 ++ test/Jamfile.v2 | 2 ++ test/mp_find.cpp | 54 ++++++++++++++++++++++++++++++++ test/mp_find_if.cpp | 50 +++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 test/mp_find.cpp create mode 100644 test/mp_find_if.cpp diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 3db3507..3a4d8b8 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -613,7 +613,10 @@ template class L, class T1, class... T, template cl template class P> using mp_find_index_if = typename detail::mp_find_index_if_impl::type; // mp_find +template using mp_find = mp_drop>; + // mp_find_if +template class P> using mp_find_if = mp_drop>; // mp_reverse // mp_fold diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 2dd97a8..395aa0d 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -46,6 +46,8 @@ run mp_partition.cpp : : : $(REQ) ; run mp_sort.cpp : : : $(REQ) ; run mp_find_index.cpp : : : $(REQ) ; run mp_find_index_if.cpp : : : $(REQ) ; +run mp_find.cpp : : : $(REQ) ; +run mp_find_if.cpp : : : $(REQ) ; # integral run integral.cpp : : : $(REQ) ; diff --git a/test/mp_find.cpp b/test/mp_find.cpp new file mode 100644 index 0000000..b9b3b2e --- /dev/null +++ b/test/mp_find.cpp @@ -0,0 +1,54 @@ + +// Copyright 2015 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 + +struct X1 {}; +struct X2 {}; +struct X3 {}; + +int main() +{ + using boost::mp_list; + using boost::mp_find; + + { + using L1 = mp_list<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L1>)); + + using L2 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L2>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + } + + { + using L3 = std::tuple<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L3>)); + + using L4 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L4>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + } + + return boost::report_errors(); +} diff --git a/test/mp_find_if.cpp b/test/mp_find_if.cpp new file mode 100644 index 0000000..72fc9e0 --- /dev/null +++ b/test/mp_find_if.cpp @@ -0,0 +1,50 @@ + +// Copyright 2015 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 + +struct X1 {}; + +int main() +{ + using boost::mp_list; + using boost::mp_find_if; + + { + using L1 = mp_list<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L1>)); + + using L2 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + } + + { + using L1 = std::tuple<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L1>)); + + using L2 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + } + + return boost::report_errors(); +}