forked from boostorg/mp11
Add mp_cond
This commit is contained in:
@@ -107,6 +107,31 @@ template<bool C, class T, template<class...> class F, class... U> using mp_eval_
|
|||||||
template<class C, class T, template<class...> class F, class... U> using mp_eval_if = typename detail::mp_eval_if_c_impl<static_cast<bool>(C::value), T, F, U...>::type;
|
template<class C, class T, template<class...> class F, class... U> using mp_eval_if = typename detail::mp_eval_if_c_impl<static_cast<bool>(C::value), T, F, U...>::type;
|
||||||
template<class C, class T, class Q, class... U> using mp_eval_if_q = typename detail::mp_eval_if_c_impl<static_cast<bool>(C::value), T, Q::template fn, U...>::type;
|
template<class C, class T, class Q, class... U> using mp_eval_if_q = typename detail::mp_eval_if_c_impl<static_cast<bool>(C::value), T, Q::template fn, U...>::type;
|
||||||
|
|
||||||
|
// mp_cond
|
||||||
|
|
||||||
|
// so elegant; so doesn't work
|
||||||
|
// template<class C, class T, class... E> using mp_cond = mp_eval_if<C, T, mp_cond, E...>;
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
template<class C, class T, class... E> struct mp_cond_impl;
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
template<class C, class T, class... E> using mp_cond = typename detail::mp_cond_impl<C, T, E...>::type;
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
template<class C, class T, class... E> using mp_cond_ = mp_eval_if<C, T, mp_cond, E...>;
|
||||||
|
|
||||||
|
template<class C, class T, class... E> struct mp_cond_impl: mp_defer<mp_cond_, C, T, E...>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
// mp_quote
|
// mp_quote
|
||||||
template<template<class...> class F> struct mp_quote
|
template<template<class...> class F> struct mp_quote
|
||||||
{
|
{
|
||||||
|
@@ -90,6 +90,8 @@ run mp_quote.cpp ;
|
|||||||
run mp_invoke.cpp ;
|
run mp_invoke.cpp ;
|
||||||
run mp_invoke_sf.cpp ;
|
run mp_invoke_sf.cpp ;
|
||||||
run mp_quote_trait.cpp ;
|
run mp_quote_trait.cpp ;
|
||||||
|
run mp_cond.cpp ;
|
||||||
|
run mp_cond_sf.cpp ;
|
||||||
|
|
||||||
# integer_sequence
|
# integer_sequence
|
||||||
run integer_sequence.cpp ;
|
run integer_sequence.cpp ;
|
||||||
|
42
test/mp_cond.cpp
Normal file
42
test/mp_cond.cpp
Normal file
@@ -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 <boost/mp11/utility.hpp>
|
||||||
|
#include <boost/mp11/integral.hpp>
|
||||||
|
#include <boost/core/lightweight_test_trait.hpp>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
using boost::mp11::mp_cond;
|
||||||
|
using boost::mp11::mp_true;
|
||||||
|
using boost::mp11::mp_false;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_cond<mp_true, char[]>, char[]>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_cond<mp_true, char[], void>, char[]>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_cond<mp_true, char[], void, void>, char[]>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_cond<mp_true, char[], void, void, void>, char[]>));
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_cond<mp_false, int, mp_true, char[]>, char[]>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_cond<mp_false, int, mp_true, char[], void>, char[]>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_cond<mp_false, int, mp_true, char[], void, void>, char[]>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_cond<mp_false, int, mp_true, char[], void, void, void>, char[]>));
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_cond<mp_false, int, mp_false, float, mp_true, char[]>, char[]>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_cond<mp_false, int, mp_false, float, mp_true, char[], void>, char[]>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_cond<mp_false, int, mp_false, float, mp_true, char[], void, void>, char[]>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_cond<mp_false, int, mp_false, float, mp_true, char[], void, void, void>, char[]>));
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_cond<mp_false, int, mp_false, float, mp_false, double, mp_true, char[]>, char[]>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_cond<mp_false, int, mp_false, float, mp_false, double, mp_true, char[], void>, char[]>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_cond<mp_false, int, mp_false, float, mp_false, double, mp_true, char[], void, void>, char[]>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_cond<mp_false, int, mp_false, float, mp_false, double, mp_true, char[], void, void, void>, char[]>));
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
43
test/mp_cond_sf.cpp
Normal file
43
test/mp_cond_sf.cpp
Normal file
@@ -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 <boost/mp11/utility.hpp>
|
||||||
|
#include <boost/mp11/integral.hpp>
|
||||||
|
#include <boost/core/lightweight_test_trait.hpp>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
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<mp_cond>));
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_cond, mp_true>));
|
||||||
|
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_cond, mp_false>));
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((mp_valid<mp_cond, mp_true, void>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((mp_valid<mp_cond, mp_true, void, void>));
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_cond, mp_false, void>));
|
||||||
|
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_cond, mp_false, void, void>));
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_cond, mp_false, void, mp_true>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((mp_valid<mp_cond, mp_false, void, mp_true, void>));
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_cond, mp_false, void, mp_false>));
|
||||||
|
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_cond, mp_false, void, mp_false, void>));
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_cond, mp_false, void, mp_false, void, mp_true>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((mp_valid<mp_cond, mp_false, void, mp_false, void, mp_true, void>));
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user