diff --git a/doc/mp11/utility.adoc b/doc/mp11/utility.adoc index 7a9777a..d55ea87 100644 --- a/doc/mp11/utility.adoc +++ b/doc/mp11/utility.adoc @@ -188,6 +188,20 @@ template using first_or_void = Like `mp_eval_or`, but takes a quoted metafunction. +## mp_valid_and_true + + template class F, class... T> using mp_valid_and_true = + mp_eval_or; + +`mp_valid_and_true` is an alias for `F` when this expression is valid, for `mp_false` otherwise. + +## mp_valid_and_true_q + + template using mp_valid_and_true_q = + mp_valid_and_true; + +Like `mp_valid_and_true`, but takes a quoted metafunction. + ## mp_cond template using mp_cond = /*...*/; diff --git a/include/boost/mp11/utility.hpp b/include/boost/mp11/utility.hpp index b3fa7a9..fbab4a3 100644 --- a/include/boost/mp11/utility.hpp +++ b/include/boost/mp11/utility.hpp @@ -161,6 +161,10 @@ template using mp_eval_if_not_q = mp_eval template class F, class... U> using mp_eval_or = mp_eval_if_not, T, F, U...>; template using mp_eval_or_q = mp_eval_or; +// mp_valid_and_true +template class F, class... T> using mp_valid_and_true = mp_eval_or; +template using mp_valid_and_true_q = mp_valid_and_true; + // mp_cond // so elegant; so doesn't work diff --git a/test/Jamfile b/test/Jamfile index 0a1be29..0e25055 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -149,6 +149,7 @@ run mp_not_fn.cpp ; run mp_eval_if_not.cpp ; run mp_eval_or.cpp ; run mp_compose.cpp ; +run mp_valid_and_true.cpp ; # integer_sequence run integer_sequence.cpp ; diff --git a/test/mp_valid_and_true.cpp b/test/mp_valid_and_true.cpp new file mode 100644 index 0000000..31cf8fd --- /dev/null +++ b/test/mp_valid_and_true.cpp @@ -0,0 +1,48 @@ +// Copyright 2022 Dmitry Arkhipov (grisumbras@gmail.com) +// +// 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 + +template +using has_size_t_difference_type + = std::is_same; + +struct X +{ +}; + +struct Y +{ + using difference_type = int; +}; + +struct Z +{ + using difference_type = std::size_t; +}; + +int main() +{ + using boost::mp11::mp_valid_and_true; + using boost::mp11::mp_valid_and_true_q; + using boost::mp11::mp_quote; + + BOOST_TEST_TRAIT_FALSE((mp_valid_and_true)); + BOOST_TEST_TRAIT_FALSE((mp_valid_and_true)); + BOOST_TEST_TRAIT_TRUE((mp_valid_and_true)); + + using Q_size_t_diff = mp_quote; + + BOOST_TEST_TRAIT_FALSE((mp_valid_and_true_q)); + BOOST_TEST_TRAIT_FALSE((mp_valid_and_true_q)); + BOOST_TEST_TRAIT_TRUE((mp_valid_and_true_q)); + + return boost::report_errors(); +}