forked from boostorg/mp11
Add mp_eval_or
This commit is contained in:
@@ -153,6 +153,10 @@ template<class C, class T, class Q, class... U> using mp_eval_if_q = typename de
|
||||
template<class C, class T, template<class...> class F, class... U> using mp_eval_if_not = mp_eval_if<mp_not<C>, T, F, U...>;
|
||||
template<class C, class T, class Q, class... U> using mp_eval_if_not_q = mp_eval_if<mp_not<C>, T, Q::template fn, U...>;
|
||||
|
||||
// mp_eval_or
|
||||
template<class T, template<class...> class F, class... U> using mp_eval_or = mp_eval_if_not<mp_valid<F, U...>, T, F, U...>;
|
||||
template<class T, class Q, class... U> using mp_eval_or_q = mp_eval_or<T, Q::template fn, U...>;
|
||||
|
||||
// mp_cond
|
||||
|
||||
// so elegant; so doesn't work
|
||||
|
@@ -125,6 +125,7 @@ run mp_cond.cpp ;
|
||||
run mp_cond_sf.cpp ;
|
||||
run mp_not_fn.cpp ;
|
||||
run mp_eval_if_not.cpp ;
|
||||
run mp_eval_or.cpp ;
|
||||
|
||||
# integer_sequence
|
||||
run integer_sequence.cpp ;
|
||||
|
51
test/mp_eval_or.cpp
Normal file
51
test/mp_eval_or.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
// Copyright 2019 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/core/lightweight_test_trait.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
template<class T> using difference_type = typename T::difference_type;
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
using difference_type = int;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp11::mp_eval_or;
|
||||
using boost::mp11::mp_eval_or_q;
|
||||
using boost::mp11::mp_identity;
|
||||
using boost::mp11::mp_quote;
|
||||
|
||||
BOOST_TEST_TRAIT_SAME(mp_eval_or<void, mp_identity>, void);
|
||||
BOOST_TEST_TRAIT_SAME(mp_eval_or<void, mp_identity, int>, mp_identity<int>);
|
||||
BOOST_TEST_TRAIT_SAME(mp_eval_or<void, mp_identity, int, int>, void);
|
||||
|
||||
using Q_identity = mp_quote<mp_identity>;
|
||||
|
||||
BOOST_TEST_TRAIT_SAME(mp_eval_or_q<void, Q_identity>, void);
|
||||
BOOST_TEST_TRAIT_SAME(mp_eval_or_q<void, Q_identity, int>, mp_identity<int>);
|
||||
BOOST_TEST_TRAIT_SAME(mp_eval_or_q<void, Q_identity, int, int>, void);
|
||||
|
||||
BOOST_TEST_TRAIT_SAME(mp_eval_or<std::ptrdiff_t, difference_type, X>, std::ptrdiff_t);
|
||||
BOOST_TEST_TRAIT_SAME(mp_eval_or<std::ptrdiff_t, difference_type, Y>, int);
|
||||
|
||||
using Q_diff_type = mp_quote<difference_type>;
|
||||
|
||||
BOOST_TEST_TRAIT_SAME(mp_eval_or_q<std::ptrdiff_t, Q_diff_type, X>, std::ptrdiff_t);
|
||||
BOOST_TEST_TRAIT_SAME(mp_eval_or_q<std::ptrdiff_t, Q_diff_type, Y>, int);
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user