From 1d1be2bbf4f88af31acd05d9d1a5757a7992f3b1 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 19 May 2017 03:22:53 +0300 Subject: [PATCH] Add mp_eval_if_q --- doc/html/mp11.html | 36 +++++++++++++++++++++++----------- doc/mp11/utility.qbk | 16 ++++++++++----- include/boost/mp11/utility.hpp | 14 +++---------- test/mp_eval_if.cpp | 15 +++++++++++++- test/mp_eval_if_sf.cpp | 19 +++++++++++++++--- 5 files changed, 69 insertions(+), 31 deletions(-) diff --git a/doc/html/mp11.html b/doc/html/mp11.html index 9f17fb1..706b518 100644 --- a/doc/html/mp11.html +++ b/doc/html/mp11.html @@ -86,13 +86,15 @@
mp_identity<T>
mp_identity_t<T>
mp_inherit<T...>
-
mp_if_c<B, T, E...>
+
mp_if_c<C, T, E...>
mp_if<C, - T, E>
-
mp_eval_if_c<B, T, F, + T, E...>
+
mp_eval_if_c<C, T, F, U...>
mp_eval_if<C, T, F, U...>
+
mp_eval_if_q<C, T, Q, + U...>
mp_valid<F, T...>
mp_defer<F, T...>
mp_quote<F>
@@ -1308,7 +1310,7 @@
template<bool C, class T, class... E> using mp_if_c = /*...*/;
 
@@ -1325,10 +1327,10 @@
-
template<class C, class T, class E> using mp_if = mp_if_c<static_cast<bool>(C::value), T, E>;
+
template<class C, class T, class E...> using mp_if = mp_if_c<static_cast<bool>(C::value), T, E...>;
 

Like mp_if_c, but the first @@ -1337,16 +1339,16 @@

template<bool C, class T, template<class...> class F, class... U> using mp_eval_if_c = /*...*/;
 

- mp_eval_if_c<B, T, F, + mp_eval_if_c<C, T, F, U...> is an alias for T when - B is true, + C is true, for F<U...> otherwise. Its purpose is to avoid evaluating F<U...> when the condition is true as it may not be valid in this case.

@@ -1365,6 +1367,18 @@
+
template<class C, class T, class Q, class... U> using mp_eval_if_q = mp_eval_if<C, T, Q::template fn, U...>;
+
+

+ Like mp_eval_if, but takes + a quoted metafunction. +

+
+
+
template<template<class...> class F, class... T> using mp_valid = /*...*/;
@@ -2415,7 +2429,7 @@
 
- +

Last revised: May 18, 2017 at 23:36:45 GMT

Last revised: May 18, 2017 at 23:57:52 GMT


diff --git a/doc/mp11/utility.qbk b/doc/mp11/utility.qbk index 23d6ce1..13b6f80 100644 --- a/doc/mp11/utility.qbk +++ b/doc/mp11/utility.qbk @@ -23,7 +23,7 @@ template struct mp_inherit: T... {}; [endsect] -[section `mp_if_c`] +[section `mp_if_c`] template using mp_if_c = /*...*/; `mp_if_c` is an alias for `T`. `mp_if_c` is an alias for `E`. Otherwise, the result is a substitution failure. @@ -34,16 +34,16 @@ template using void_if_5 = mp_if_c; // `void` when `I::value` is 5, substitution failure otherwise [endsect] -[section `mp_if`] - template using mp_if = mp_if_c(C::value), T, E>; +[section `mp_if`] + template using mp_if = mp_if_c(C::value), T, E...>; Like `mp_if_c`, but the first argument is a type. [endsect] -[section `mp_eval_if_c`] +[section `mp_eval_if_c`] template class F, class... U> using mp_eval_if_c = /*...*/; -`mp_eval_if_c` is an alias for `T` when `B` is `true`, for `F` otherwise. Its purpose +`mp_eval_if_c` is an alias for `T` when `C` is `true`, for `F` otherwise. Its purpose is to avoid evaluating `F` when the condition is `true` as it may not be valid in this case. [endsect] @@ -53,6 +53,12 @@ is to avoid evaluating `F` when the condition is `true` as it may not be v Like `mp_eval_if_c`, but the first argument is a type. [endsect] +[section `mp_eval_if_q`] + template using mp_eval_if_q = mp_eval_if; + +Like `mp_eval_if`, but takes a quoted metafunction. +[endsect] + [section `mp_valid`] template class F, class... T> using mp_valid = /*...*/; diff --git a/include/boost/mp11/utility.hpp b/include/boost/mp11/utility.hpp index 5590e09..1439596 100644 --- a/include/boost/mp11/utility.hpp +++ b/include/boost/mp11/utility.hpp @@ -105,23 +105,15 @@ template class F, class... U> struct mp_eval_if_c_im template class F, class... U> using mp_eval_if_c = typename detail::mp_eval_if_c_impl::type; template class F, class... U> using mp_eval_if = typename detail::mp_eval_if_c_impl(C::value), T, F, U...>::type; +template using mp_eval_if_q = typename detail::mp_eval_if_c_impl(C::value), T, Q::template fn, U...>::type; // mp_quote template class F> struct mp_quote { -#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1910 && BOOST_MSVC >= 1900 ) -#else -private: -#endif - - template struct _fn { using type = F; }; - -public: - - // the indirection through _fn works around the language inability + // the indirection through mp_defer works around the language inability // to expand T... into a fixed parameter list of an alias template - template using fn = typename _fn::type; + template using fn = typename mp_defer::type; }; // mp_unquote diff --git a/test/mp_eval_if.cpp b/test/mp_eval_if.cpp index 1c8ed39..7e44c67 100644 --- a/test/mp_eval_if.cpp +++ b/test/mp_eval_if.cpp @@ -1,5 +1,5 @@ -// Copyright 2015 Peter Dimov. +// Copyright 2015, 2017 Peter Dimov. // // Distributed under the Boost Software License, Version 1.0. // @@ -21,19 +21,32 @@ int main() BOOST_TEST_TRAIT_TRUE((std::is_same, mp_identity>)); using boost::mp11::mp_eval_if; + using boost::mp11::mp_eval_if_q; + using boost::mp11::mp_quote; + + using qt_identity = mp_quote; BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); BOOST_TEST_TRAIT_TRUE((std::is_same, mp_identity>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_identity>)); + using boost::mp11::mp_int; BOOST_TEST_TRAIT_TRUE((std::is_same, char[], mp_identity, void, void, void>, char[]>)); BOOST_TEST_TRAIT_TRUE((std::is_same, char[], mp_identity, void()>, mp_identity>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[], qt_identity, void, void, void>, char[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[], qt_identity, void()>, mp_identity>)); + using boost::mp11::mp_size_t; BOOST_TEST_TRAIT_TRUE((std::is_same, char[], mp_identity, void, void, void>, char[]>)); BOOST_TEST_TRAIT_TRUE((std::is_same, char[], mp_identity, void()>, mp_identity>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[], qt_identity, void, void, void>, char[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, char[], qt_identity, void()>, mp_identity>)); + return boost::report_errors(); } diff --git a/test/mp_eval_if_sf.cpp b/test/mp_eval_if_sf.cpp index 8eca74e..aed1191 100644 --- a/test/mp_eval_if_sf.cpp +++ b/test/mp_eval_if_sf.cpp @@ -1,5 +1,5 @@ -// Copyright 2017 Peter Dimov. +// Copyright 2017 Peter Dimov. // // Distributed under the Boost Software License, Version 1.0. // @@ -12,14 +12,15 @@ #include using boost::mp11::mp_eval_if; +using boost::mp11::mp_eval_if_q; using boost::mp11::mp_identity_t; +using boost::mp11::mp_valid; +using boost::mp11::mp_quote; template using eval_if = mp_eval_if; int main() { - using boost::mp11::mp_valid; - BOOST_TEST_TRAIT_TRUE((mp_valid)); BOOST_TEST_TRAIT_TRUE((mp_valid)); BOOST_TEST_TRAIT_TRUE((mp_valid)); @@ -30,5 +31,17 @@ int main() BOOST_TEST_TRAIT_FALSE((mp_valid)); BOOST_TEST_TRAIT_FALSE((mp_valid)); + using Qi = mp_quote; + + BOOST_TEST_TRAIT_TRUE((mp_valid)); + BOOST_TEST_TRAIT_TRUE((mp_valid)); + BOOST_TEST_TRAIT_TRUE((mp_valid)); + BOOST_TEST_TRAIT_TRUE((mp_valid)); + + BOOST_TEST_TRAIT_FALSE((mp_valid)); + BOOST_TEST_TRAIT_TRUE((mp_valid)); + BOOST_TEST_TRAIT_FALSE((mp_valid)); + BOOST_TEST_TRAIT_FALSE((mp_valid)); + return boost::report_errors(); }