From 30fcc21d8b093625ee30d2f9595f51429780eedd Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 14 Oct 2017 02:53:38 +0300 Subject: [PATCH] Add mp_cond --- include/boost/mp11/utility.hpp | 25 ++++++++++++++++++++ test/Jamfile | 2 ++ test/mp_cond.cpp | 42 +++++++++++++++++++++++++++++++++ test/mp_cond_sf.cpp | 43 ++++++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 test/mp_cond.cpp create mode 100644 test/mp_cond_sf.cpp diff --git a/include/boost/mp11/utility.hpp b/include/boost/mp11/utility.hpp index f82d613..5935e6d 100644 --- a/include/boost/mp11/utility.hpp +++ b/include/boost/mp11/utility.hpp @@ -107,6 +107,31 @@ template class F, class... U> using mp_eval_ template class F, class... U> using mp_eval_if = typename detail::mp_eval_if_c_impl(C::value), T, F, U...>::type; template using mp_eval_if_q = typename detail::mp_eval_if_c_impl(C::value), T, Q::template fn, U...>::type; +// mp_cond + +// so elegant; so doesn't work +// template using mp_cond = mp_eval_if; + +namespace detail +{ + +template struct mp_cond_impl; + +} // namespace detail + +template using mp_cond = typename detail::mp_cond_impl::type; + +namespace detail +{ + +template using mp_cond_ = mp_eval_if; + +template struct mp_cond_impl: mp_defer +{ +}; + +} // namespace detail + // mp_quote template class F> struct mp_quote { diff --git a/test/Jamfile b/test/Jamfile index 54968ae..1f85aeb 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -90,6 +90,8 @@ run mp_quote.cpp ; run mp_invoke.cpp ; run mp_invoke_sf.cpp ; run mp_quote_trait.cpp ; +run mp_cond.cpp ; +run mp_cond_sf.cpp ; # integer_sequence run integer_sequence.cpp ; diff --git a/test/mp_cond.cpp b/test/mp_cond.cpp new file mode 100644 index 0000000..08a625f --- /dev/null +++ b/test/mp_cond.cpp @@ -0,0 +1,42 @@ + +// 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 + +int main() +{ + using boost::mp11::mp_cond; + using boost::mp11::mp_true; + using boost::mp11::mp_false; + + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + + return boost::report_errors(); +} diff --git a/test/mp_cond_sf.cpp b/test/mp_cond_sf.cpp new file mode 100644 index 0000000..c1bb4de --- /dev/null +++ b/test/mp_cond_sf.cpp @@ -0,0 +1,43 @@ + +// 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 + +int main() +{ + using boost::mp11::mp_cond; + using boost::mp11::mp_true; + using boost::mp11::mp_false; + using boost::mp11::mp_valid; + + BOOST_TEST_TRAIT_FALSE((mp_valid)); + + BOOST_TEST_TRAIT_FALSE((mp_valid)); + BOOST_TEST_TRAIT_FALSE((mp_valid)); + + BOOST_TEST_TRAIT_TRUE((mp_valid)); + BOOST_TEST_TRAIT_TRUE((mp_valid)); + + BOOST_TEST_TRAIT_FALSE((mp_valid)); + BOOST_TEST_TRAIT_FALSE((mp_valid)); + + BOOST_TEST_TRAIT_FALSE((mp_valid)); + BOOST_TEST_TRAIT_TRUE((mp_valid)); + + BOOST_TEST_TRAIT_FALSE((mp_valid)); + BOOST_TEST_TRAIT_FALSE((mp_valid)); + + BOOST_TEST_TRAIT_FALSE((mp_valid)); + BOOST_TEST_TRAIT_TRUE((mp_valid)); + + return boost::report_errors(); +}