From 543a0f755e19a667d2a75bc736de5d7fcf8e62e0 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 12 May 2017 19:21:27 +0300 Subject: [PATCH] Add mp_apply_q --- doc/html/mp11.html | 18 +++++- doc/mp11/list.qbk | 8 ++- include/boost/mp11/list.hpp | 2 + test/Jamfile.v2 | 1 + test/mp_apply_q.cpp | 113 ++++++++++++++++++++++++++++++++++++ 5 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 test/mp_apply_q.cpp diff --git a/doc/html/mp11.html b/doc/html/mp11.html index fd46376..1c96c26 100644 --- a/doc/html/mp11.html +++ b/doc/html/mp11.html @@ -70,6 +70,8 @@ Y>
mp_apply<F, L>
+
mp_apply_q<Q, + L>
mp_append<L...>
mp_replace_front<L, T>
mp_replace_first<L, T>
@@ -734,7 +736,7 @@
template<template<class...> class F, class L> using mp_apply = mp_rename<L, F>;
 

- mp_apply<F, L> applies the metafunction F to the contents of the list L, that is, mp_rename<F, L<T...>> + mp_apply<F, L> applies the metafunction F to the contents of the list L, that is, mp_apply<F, L<T...>> is an alias for F<T...>. (mp_apply is the same as mp_rename with the arguments @@ -743,6 +745,18 @@

+
template<class Q, class L> using mp_apply_q = mp_apply<Q::template fn, L>;
+
+

+ Same as mp_apply, but takes + a quoted metafunction. +

+
+
+
template<class... L> using mp_append = /*...*/;
@@ -1854,7 +1868,7 @@
 
- +

Last revised: May 10, 2017 at 20:23:11 GMT

Last revised: May 12, 2017 at 16:19:34 GMT


diff --git a/doc/mp11/list.qbk b/doc/mp11/list.qbk index 4c4dcd0..67cdfc8 100644 --- a/doc/mp11/list.qbk +++ b/doc/mp11/list.qbk @@ -88,10 +88,16 @@ is an alias for `L`. [section `mp_apply`] template class F, class L> using mp_apply = mp_rename; -`mp_apply` applies the metafunction `F` to the contents of the list `L`, that is, `mp_rename>` is an alias for `F`. +`mp_apply` applies the metafunction `F` to the contents of the list `L`, that is, `mp_apply>` is an alias for `F`. (`mp_apply` is the same as `mp_rename` with the arguments reversed.) [endsect] +[section `mp_apply_q`] + template using mp_apply_q = mp_apply; + +Same as `mp_apply`, but takes a quoted metafunction. +[endsect] + [section `mp_append`] template using mp_append = /*...*/; diff --git a/include/boost/mp11/list.hpp b/include/boost/mp11/list.hpp index ef205b7..5795d0a 100644 --- a/include/boost/mp11/list.hpp +++ b/include/boost/mp11/list.hpp @@ -150,6 +150,8 @@ template class B> using mp_rename = typename detail: template class F, class L> using mp_apply = typename detail::mp_rename_impl::type; +template using mp_apply_q = typename detail::mp_rename_impl::type; + // mp_replace_front namespace detail { diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 7fa0101..c627c6b 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -29,6 +29,7 @@ run mp_append_2.cpp : : : $(REQ) ; run mp_replace_front.cpp : : : $(REQ) ; run mp_replace_second.cpp : : : $(REQ) ; run mp_replace_third.cpp : : : $(REQ) ; +run mp_apply_q.cpp : : : $(REQ) ; # algorithm run mp_assign.cpp : : : $(REQ) ; diff --git a/test/mp_apply_q.cpp b/test/mp_apply_q.cpp new file mode 100644 index 0000000..d2a47c0 --- /dev/null +++ b/test/mp_apply_q.cpp @@ -0,0 +1,113 @@ + +// 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 + +template struct X {}; +template using Y = X; + +struct Q +{ + template using fn = X; +}; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_quote; + using boost::mp11::mp_apply_q; + + using L1 = mp_list<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L1>, mp_list<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L1>, std::tuple<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L1>, X<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L1>, Y<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, X<>>)); + + using L2 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L2>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L2>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L2>, X>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L2>, Y>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, X>)); + + using L3 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L3>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L3>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L3>, X>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L3>, Y>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L3>, std::pair>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, X>)); + + using L4 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L4>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L4>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L4>, X>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L4>, Y>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, X>)); + + // + + using L5 = std::tuple<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L5>, mp_list<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L5>, std::tuple<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L5>, X<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L5>, Y<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, X<>>)); + + using L6 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L6>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L6>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L6>, X>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L6>, Y>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, X>)); + + using L7 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L7>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L7>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L7>, X>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L7>, Y>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L7>, std::pair>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, X>)); + + using L8 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L8>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L8>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L8>, X>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L8>, Y>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, X>)); + + // + + using L9 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L9>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L9>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L9>, X>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L9>, Y>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L9>, std::pair>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, X>)); + + // + + return boost::report_errors(); +}