forked from boostorg/mp11
SFINAE-fail mp_eval_if when F<U...> is invalid
This commit is contained in:
@@ -52,27 +52,6 @@ template<class T, class E> struct mp_if_c_impl<false, T, E>
|
|||||||
template<bool C, class T, class... E> using mp_if_c = typename detail::mp_if_c_impl<C, T, E...>::type;
|
template<bool C, class T, class... E> using mp_if_c = typename detail::mp_if_c_impl<C, T, E...>::type;
|
||||||
template<class C, class T, class... E> using mp_if = typename detail::mp_if_c_impl<static_cast<bool>(C::value), T, E...>::type;
|
template<class C, class T, class... E> using mp_if = typename detail::mp_if_c_impl<static_cast<bool>(C::value), T, E...>::type;
|
||||||
|
|
||||||
// mp_eval_if, mp_eval_if_c
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
|
|
||||||
template<bool C, class T, template<class...> class F, class... U> struct mp_eval_if_c_impl;
|
|
||||||
|
|
||||||
template<class T, template<class...> class F, class... U> struct mp_eval_if_c_impl<true, T, F, U...>
|
|
||||||
{
|
|
||||||
using type = T;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T, template<class...> class F, class... U> struct mp_eval_if_c_impl<false, T, F, U...>
|
|
||||||
{
|
|
||||||
using type = F<U...>;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
template<bool C, class T, template<class...> class F, class... U> using mp_eval_if_c = typename detail::mp_eval_if_c_impl<C, 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;
|
|
||||||
|
|
||||||
// mp_valid
|
// mp_valid
|
||||||
// implementation by Bruno Dutra (by the name is_evaluable)
|
// implementation by Bruno Dutra (by the name is_evaluable)
|
||||||
namespace detail
|
namespace detail
|
||||||
@@ -107,6 +86,26 @@ struct mp_no_type
|
|||||||
|
|
||||||
template<template<class...> class F, class... T> using mp_defer = mp_if<mp_valid<F, T...>, detail::mp_defer_impl<F, T...>, detail::mp_no_type>;
|
template<template<class...> class F, class... T> using mp_defer = mp_if<mp_valid<F, T...>, detail::mp_defer_impl<F, T...>, detail::mp_no_type>;
|
||||||
|
|
||||||
|
// mp_eval_if, mp_eval_if_c
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
template<bool C, class T, template<class...> class F, class... U> struct mp_eval_if_c_impl;
|
||||||
|
|
||||||
|
template<class T, template<class...> class F, class... U> struct mp_eval_if_c_impl<true, T, F, U...>
|
||||||
|
{
|
||||||
|
using type = T;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T, template<class...> class F, class... U> struct mp_eval_if_c_impl<false, T, F, U...>: mp_defer<F, U...>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
template<bool C, class T, template<class...> class F, class... U> using mp_eval_if_c = typename detail::mp_eval_if_c_impl<C, 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;
|
||||||
|
|
||||||
// mp_quote
|
// mp_quote
|
||||||
template<template<class...> class F> struct mp_quote
|
template<template<class...> class F> struct mp_quote
|
||||||
{
|
{
|
||||||
|
@@ -77,6 +77,7 @@ run mp_inherit.cpp : : : $(REQ) ;
|
|||||||
run mp_if.cpp : : : $(REQ) ;
|
run mp_if.cpp : : : $(REQ) ;
|
||||||
run mp_if_sf.cpp : : : $(REQ) ;
|
run mp_if_sf.cpp : : : $(REQ) ;
|
||||||
run mp_eval_if.cpp : : : $(REQ) ;
|
run mp_eval_if.cpp : : : $(REQ) ;
|
||||||
|
run mp_eval_if_sf.cpp : : : $(REQ) ;
|
||||||
run mp_valid.cpp : : : $(REQ) ;
|
run mp_valid.cpp : : : $(REQ) ;
|
||||||
run mp_defer.cpp : : : $(REQ) ;
|
run mp_defer.cpp : : : $(REQ) ;
|
||||||
run mp_quote.cpp : : : $(REQ) ;
|
run mp_quote.cpp : : : $(REQ) ;
|
||||||
|
34
test/mp_eval_if_sf.cpp
Normal file
34
test/mp_eval_if_sf.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
|
||||||
|
// 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/core/lightweight_test_trait.hpp>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
using boost::mp11::mp_eval_if;
|
||||||
|
using boost::mp11::mp_identity_t;
|
||||||
|
|
||||||
|
template<class C, class... A> using eval_if = mp_eval_if<C, void, mp_identity_t, A...>;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
using boost::mp11::mp_valid;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((mp_valid<eval_if, std::true_type>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((mp_valid<eval_if, std::true_type, void>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((mp_valid<eval_if, std::true_type, void, void>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((mp_valid<eval_if, std::true_type, void, void, void>));
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_FALSE((mp_valid<eval_if, std::false_type>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((mp_valid<eval_if, std::false_type, void>));
|
||||||
|
BOOST_TEST_TRAIT_FALSE((mp_valid<eval_if, std::false_type, void, void>));
|
||||||
|
BOOST_TEST_TRAIT_FALSE((mp_valid<eval_if, std::false_type, void, void, void>));
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user