1
0
forked from boostorg/mp11

Add mp_eval_or

This commit is contained in:
Peter Dimov
2019-02-14 21:03:13 +02:00
parent ca7e140827
commit fc8bfcf601
3 changed files with 56 additions and 0 deletions

View File

@@ -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

View File

@@ -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
View 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();
}