From 6db4019341d48f20a0f9f526bb8720945156815c Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 25 May 2017 21:31:03 +0300 Subject: [PATCH] Add mp_transform_if_q --- doc/html/mp11.html | 14 ++++- doc/mp11/algorithm.qbk | 6 +++ include/boost/mp11/algorithm.hpp | 9 +++- test/Jamfile.v2 | 1 + test/mp_transform_if_q.cpp | 87 ++++++++++++++++++++++++++++++++ 5 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 test/mp_transform_if_q.cpp diff --git a/doc/html/mp11.html b/doc/html/mp11.html index 265dc7e..5c98250 100644 --- a/doc/html/mp11.html +++ b/doc/html/mp11.html @@ -107,6 +107,7 @@
mp_transform<F, L...>
mp_transform_q<Q, L...>
mp_transform_if<P, F, L...>
+
mp_transform_if_q<Qp, Qf, L...>
mp_fill<L, V>
mp_count<L, V>
mp_count_if<L, P>
@@ -1526,6 +1527,17 @@
+
template<class Qp, class Qf, class... L> using mp_transform_if_q = mp_transform_if<Qp::template fn, Qf::template fn, L...>;
+
+

+ As mp_transform_if, but + takes a quoted metafunction. +

+
+
+
template<class L, class V> using mp_fill = /*...*/;
@@ -2492,7 +2504,7 @@
 
- +

Last revised: May 24, 2017 at 17:55:07 GMT

Last revised: May 25, 2017 at 18:29:52 GMT


diff --git a/doc/mp11/algorithm.qbk b/doc/mp11/algorithm.qbk index 8a555db..17f1649 100644 --- a/doc/mp11/algorithm.qbk +++ b/doc/mp11/algorithm.qbk @@ -39,6 +39,12 @@ As `mp_transform`, but takes a quoted metafunction. `F`, and returns the result, where `Ti` are the corresponding elements of `Li`. [endsect] +[section `mp_transform_if_q`] + template using mp_transform_if_q = mp_transform_if; + +As `mp_transform_if`, but takes a quoted metafunction. +[endsect] + [section `mp_fill`] template using mp_fill = /*...*/; diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index e31e3b7..5edfaac 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -125,14 +125,18 @@ namespace detail template class P, template class F, class... L> struct mp_transform_if_impl { // the stupid quote-unquote dance avoids "pack expansion used as argument for non-pack parameter of alias template" + + using Qp = mp_quote

; + using Qf = mp_quote; + #if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1910 ) - template struct _f_ { using type = mp_eval_if, U...>>, mp_first>, mp_quote::template fn, U...>; }; + template struct _f_ { using type = mp_eval_if_q>, mp_first>, Qf, U...>; }; template using _f = typename _f_::type; #else - template using _f = mp_eval_if, U...>>, mp_first>, mp_quote::template fn, U...>; + template using _f = mp_eval_if_q>, mp_first>, Qf, U...>; #endif @@ -142,6 +146,7 @@ template class P, template class F, class... L> str } // namespace detail template class P, template class F, class... L> using mp_transform_if = typename detail::mp_transform_if_impl::type; +template using mp_transform_if_q = typename detail::mp_transform_if_impl::type; // mp_fill namespace detail diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 277bc4f..362df65 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -37,6 +37,7 @@ run mp_clear.cpp : : : $(REQ) ; run mp_transform.cpp : : : $(REQ) ; run mp_transform_sf.cpp : : : $(REQ) ; run mp_transform_if.cpp : : : $(REQ) ; +run mp_transform_if_q.cpp : : : $(REQ) ; run mp_fill.cpp : : : $(REQ) ; run mp_count.cpp : : : $(REQ) ; run mp_count_if.cpp : : : $(REQ) ; diff --git a/test/mp_transform_if_q.cpp b/test/mp_transform_if_q.cpp new file mode 100644 index 0000000..b2087be --- /dev/null +++ b/test/mp_transform_if_q.cpp @@ -0,0 +1,87 @@ + +// Copyright 2015, 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 +#include +#include +#include +#include +#include +#include +#include + +struct X1 {}; +struct X2 {}; +struct X3 {}; +struct X4 {}; + +using boost::mp11::mp_not; +using boost::mp11::mp_quote; + +template using add_pointer = T*; +using Q_add_pointer = mp_quote; + +template using is_not_ref = mp_not>; +using Q_is_not_ref = mp_quote; + +template using second = T2; +using Q_second = mp_quote; + +template using third = T3; +using Q_third = mp_quote; + +template using fourth = T4; +using Q_fourth = mp_quote; + +template using fifth = T5; +using Q_fifth = mp_quote; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_transform_if_q; + using boost::mp11::mp_size_t; + using boost::mp11::mp_size; + using boost::mp11::mp_fill; + using boost::mp11::mp_iota; + + using L1 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + + using L2 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + + using L3 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>)); + + // + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::pair>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same>>, mp_list, X2&, mp_size_t<2>, X4 const&>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>>, std::tuple, X2&, mp_size_t<2>, X4 const&>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>>, std::pair, X2&>>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same>>, mp_list, X2&, mp_size_t<2>, X4 const&>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>>, std::tuple, X2&, mp_size_t<2>, X4 const&>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>>, std::pair, X2&>>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same>>, mp_list, X2&, mp_size_t<2>, X4 const&>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>>, std::tuple, X2&, mp_size_t<2>, X4 const&>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>>, std::pair, X2&>>)); + + // + + return boost::report_errors(); +}