forked from boostorg/mp11
Add mp_apply_q
This commit is contained in:
@@ -70,6 +70,8 @@
|
|||||||
<span class="identifier">Y</span><span class="special">></span></code></a></span></dt>
|
<span class="identifier">Y</span><span class="special">></span></code></a></span></dt>
|
||||||
<dt><span class="section"><a href="mp11.html#mp11.reference.list.mp_apply_f_l"><code class="computeroutput"><span class="identifier">mp_apply</span><span class="special"><</span><span class="identifier">F</span><span class="special">,</span>
|
<dt><span class="section"><a href="mp11.html#mp11.reference.list.mp_apply_f_l"><code class="computeroutput"><span class="identifier">mp_apply</span><span class="special"><</span><span class="identifier">F</span><span class="special">,</span>
|
||||||
<span class="identifier">L</span><span class="special">></span></code></a></span></dt>
|
<span class="identifier">L</span><span class="special">></span></code></a></span></dt>
|
||||||
|
<dt><span class="section"><a href="mp11.html#mp11.reference.list.mp_apply_q_q_l"><code class="computeroutput"><span class="identifier">mp_apply_q</span><span class="special"><</span><span class="identifier">Q</span><span class="special">,</span>
|
||||||
|
<span class="identifier">L</span><span class="special">></span></code></a></span></dt>
|
||||||
<dt><span class="section"><a href="mp11.html#mp11.reference.list.mp_append_l"><code class="computeroutput"><span class="identifier">mp_append</span><span class="special"><</span><span class="identifier">L</span><span class="special">...></span></code></a></span></dt>
|
<dt><span class="section"><a href="mp11.html#mp11.reference.list.mp_append_l"><code class="computeroutput"><span class="identifier">mp_append</span><span class="special"><</span><span class="identifier">L</span><span class="special">...></span></code></a></span></dt>
|
||||||
<dt><span class="section"><a href="mp11.html#mp11.reference.list.mp_replace_front_l_t"><code class="computeroutput"><span class="identifier">mp_replace_front</span><span class="special"><</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">T</span><span class="special">></span></code></a></span></dt>
|
<dt><span class="section"><a href="mp11.html#mp11.reference.list.mp_replace_front_l_t"><code class="computeroutput"><span class="identifier">mp_replace_front</span><span class="special"><</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">T</span><span class="special">></span></code></a></span></dt>
|
||||||
<dt><span class="section"><a href="mp11.html#mp11.reference.list.mp_replace_first_l_t"><code class="computeroutput"><span class="identifier">mp_replace_first</span><span class="special"><</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">T</span><span class="special">></span></code></a></span></dt>
|
<dt><span class="section"><a href="mp11.html#mp11.reference.list.mp_replace_first_l_t"><code class="computeroutput"><span class="identifier">mp_replace_first</span><span class="special"><</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">T</span><span class="special">></span></code></a></span></dt>
|
||||||
@@ -734,7 +736,7 @@
|
|||||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span><span class="special">...></span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">L</span><span class="special">></span> <span class="keyword">using</span> <span class="identifier">mp_apply</span> <span class="special">=</span> <span class="identifier">mp_rename</span><span class="special"><</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">F</span><span class="special">>;</span>
|
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span><span class="special">...></span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">L</span><span class="special">></span> <span class="keyword">using</span> <span class="identifier">mp_apply</span> <span class="special">=</span> <span class="identifier">mp_rename</span><span class="special"><</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">F</span><span class="special">>;</span>
|
||||||
</pre>
|
</pre>
|
||||||
<p>
|
<p>
|
||||||
<code class="computeroutput"><span class="identifier">mp_apply</span><span class="special"><</span><span class="identifier">F</span><span class="special">,</span> <span class="identifier">L</span><span class="special">></span></code> applies the metafunction <code class="computeroutput"><span class="identifier">F</span></code> to the contents of the list <code class="computeroutput"><span class="identifier">L</span></code>, that is, <code class="computeroutput"><span class="identifier">mp_rename</span><span class="special"><</span><span class="identifier">F</span><span class="special">,</span> <span class="identifier">L</span><span class="special"><</span><span class="identifier">T</span><span class="special">...>></span></code>
|
<code class="computeroutput"><span class="identifier">mp_apply</span><span class="special"><</span><span class="identifier">F</span><span class="special">,</span> <span class="identifier">L</span><span class="special">></span></code> applies the metafunction <code class="computeroutput"><span class="identifier">F</span></code> to the contents of the list <code class="computeroutput"><span class="identifier">L</span></code>, that is, <code class="computeroutput"><span class="identifier">mp_apply</span><span class="special"><</span><span class="identifier">F</span><span class="special">,</span> <span class="identifier">L</span><span class="special"><</span><span class="identifier">T</span><span class="special">...>></span></code>
|
||||||
is an alias for <code class="computeroutput"><span class="identifier">F</span><span class="special"><</span><span class="identifier">T</span><span class="special">...></span></code>.
|
is an alias for <code class="computeroutput"><span class="identifier">F</span><span class="special"><</span><span class="identifier">T</span><span class="special">...></span></code>.
|
||||||
(<code class="computeroutput"><span class="identifier">mp_apply</span></code> is the same as
|
(<code class="computeroutput"><span class="identifier">mp_apply</span></code> is the same as
|
||||||
<code class="computeroutput"><span class="identifier">mp_rename</span></code> with the arguments
|
<code class="computeroutput"><span class="identifier">mp_rename</span></code> with the arguments
|
||||||
@@ -743,6 +745,18 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<div class="titlepage"><div><div><h4 class="title">
|
<div class="titlepage"><div><div><h4 class="title">
|
||||||
|
<a name="mp11.reference.list.mp_apply_q_q_l"></a><a class="link" href="mp11.html#mp11.reference.list.mp_apply_q_q_l" title="mp_apply_q<Q, L>"><code class="computeroutput"><span class="identifier">mp_apply_q</span><span class="special"><</span><span class="identifier">Q</span><span class="special">,</span>
|
||||||
|
<span class="identifier">L</span><span class="special">></span></code></a>
|
||||||
|
</h4></div></div></div>
|
||||||
|
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Q</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">L</span><span class="special">></span> <span class="keyword">using</span> <span class="identifier">mp_apply_q</span> <span class="special">=</span> <span class="identifier">mp_apply</span><span class="special"><</span><span class="identifier">Q</span><span class="special">::</span><span class="keyword">template</span> <span class="identifier">fn</span><span class="special">,</span> <span class="identifier">L</span><span class="special">>;</span>
|
||||||
|
</pre>
|
||||||
|
<p>
|
||||||
|
Same as <code class="computeroutput"><span class="identifier">mp_apply</span></code>, but takes
|
||||||
|
a quoted metafunction.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="section">
|
||||||
|
<div class="titlepage"><div><div><h4 class="title">
|
||||||
<a name="mp11.reference.list.mp_append_l"></a><a class="link" href="mp11.html#mp11.reference.list.mp_append_l" title="mp_append<L...>"><code class="computeroutput"><span class="identifier">mp_append</span><span class="special"><</span><span class="identifier">L</span><span class="special">...></span></code></a>
|
<a name="mp11.reference.list.mp_append_l"></a><a class="link" href="mp11.html#mp11.reference.list.mp_append_l" title="mp_append<L...>"><code class="computeroutput"><span class="identifier">mp_append</span><span class="special"><</span><span class="identifier">L</span><span class="special">...></span></code></a>
|
||||||
</h4></div></div></div>
|
</h4></div></div></div>
|
||||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span><span class="special">...</span> <span class="identifier">L</span><span class="special">></span> <span class="keyword">using</span> <span class="identifier">mp_append</span> <span class="special">=</span> <span class="comment">/*...*/</span><span class="special">;</span>
|
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span><span class="special">...</span> <span class="identifier">L</span><span class="special">></span> <span class="keyword">using</span> <span class="identifier">mp_append</span> <span class="special">=</span> <span class="comment">/*...*/</span><span class="special">;</span>
|
||||||
@@ -1854,7 +1868,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||||
<td align="left"><p><small>Last revised: May 10, 2017 at 20:23:11 GMT</small></p></td>
|
<td align="left"><p><small>Last revised: May 12, 2017 at 16:19:34 GMT</small></p></td>
|
||||||
<td align="right"><div class="copyright-footer"></div></td>
|
<td align="right"><div class="copyright-footer"></div></td>
|
||||||
</tr></table>
|
</tr></table>
|
||||||
<hr>
|
<hr>
|
||||||
|
@@ -88,10 +88,16 @@ is an alias for `L<U..., T...>`.
|
|||||||
[section `mp_apply<F, L>`]
|
[section `mp_apply<F, L>`]
|
||||||
template<template<class...> class F, class L> using mp_apply = mp_rename<L, F>;
|
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...>>` is an alias for `F<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 reversed.)
|
(`mp_apply` is the same as `mp_rename` with the arguments reversed.)
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
|
[section `mp_apply_q<Q, L>`]
|
||||||
|
template<class Q, class L> using mp_apply_q = mp_apply<Q::template fn, L>;
|
||||||
|
|
||||||
|
Same as `mp_apply`, but takes a quoted metafunction.
|
||||||
|
[endsect]
|
||||||
|
|
||||||
[section `mp_append<L...>`]
|
[section `mp_append<L...>`]
|
||||||
template<class... L> using mp_append = /*...*/;
|
template<class... L> using mp_append = /*...*/;
|
||||||
|
|
||||||
|
@@ -150,6 +150,8 @@ template<class A, template<class...> class B> using mp_rename = typename detail:
|
|||||||
|
|
||||||
template<template<class...> class F, class L> using mp_apply = typename detail::mp_rename_impl<L, F>::type;
|
template<template<class...> class F, class L> using mp_apply = typename detail::mp_rename_impl<L, F>::type;
|
||||||
|
|
||||||
|
template<class Q, class L> using mp_apply_q = typename detail::mp_rename_impl<L, Q::template fn>::type;
|
||||||
|
|
||||||
// mp_replace_front<L, T>
|
// mp_replace_front<L, T>
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
@@ -29,6 +29,7 @@ run mp_append_2.cpp : : : $(REQ) ;
|
|||||||
run mp_replace_front.cpp : : : $(REQ) ;
|
run mp_replace_front.cpp : : : $(REQ) ;
|
||||||
run mp_replace_second.cpp : : : $(REQ) ;
|
run mp_replace_second.cpp : : : $(REQ) ;
|
||||||
run mp_replace_third.cpp : : : $(REQ) ;
|
run mp_replace_third.cpp : : : $(REQ) ;
|
||||||
|
run mp_apply_q.cpp : : : $(REQ) ;
|
||||||
|
|
||||||
# algorithm
|
# algorithm
|
||||||
run mp_assign.cpp : : : $(REQ) ;
|
run mp_assign.cpp : : : $(REQ) ;
|
||||||
|
113
test/mp_apply_q.cpp
Normal file
113
test/mp_apply_q.cpp
Normal file
@@ -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 <boost/core/lightweight_test_trait.hpp>
|
||||||
|
#include <boost/mp11/list.hpp>
|
||||||
|
#include <boost/mp11/utility.hpp>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <tuple>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
template<class... T> struct X {};
|
||||||
|
template<class... T> using Y = X<T...>;
|
||||||
|
|
||||||
|
struct Q
|
||||||
|
{
|
||||||
|
template<class... T> using fn = X<T...>;
|
||||||
|
};
|
||||||
|
|
||||||
|
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<mp_apply_q<mp_quote<mp_list>, L1>, mp_list<>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<std::tuple>, L1>, std::tuple<>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<X>, L1>, X<>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<Y>, L1>, Y<>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<Q, L1>, X<>>));
|
||||||
|
|
||||||
|
using L2 = mp_list<char>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<mp_list>, L2>, mp_list<char>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<std::tuple>, L2>, std::tuple<char>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<X>, L2>, X<char>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<Y>, L2>, Y<char>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<Q, L2>, X<char>>));
|
||||||
|
|
||||||
|
using L3 = mp_list<char, double>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<mp_list>, L3>, mp_list<char, double>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<std::tuple>, L3>, std::tuple<char, double>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<X>, L3>, X<char, double>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<Y>, L3>, Y<char, double>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<std::pair>, L3>, std::pair<char, double>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<Q, L3>, X<char, double>>));
|
||||||
|
|
||||||
|
using L4 = mp_list<int, char, float>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<mp_list>, L4>, mp_list<int, char, float>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<std::tuple>, L4>, std::tuple<int, char, float>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<X>, L4>, X<int, char, float>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<Y>, L4>, Y<int, char, float>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<Q, L4>, X<int, char, float>>));
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
using L5 = std::tuple<>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<mp_list>, L5>, mp_list<>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<std::tuple>, L5>, std::tuple<>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<X>, L5>, X<>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<Y>, L5>, Y<>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<Q, L5>, X<>>));
|
||||||
|
|
||||||
|
using L6 = std::tuple<char>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<mp_list>, L6>, mp_list<char>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<std::tuple>, L6>, std::tuple<char>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<X>, L6>, X<char>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<Y>, L6>, Y<char>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<Q, L6>, X<char>>));
|
||||||
|
|
||||||
|
using L7 = std::tuple<char, double>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<mp_list>, L7>, mp_list<char, double>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<std::tuple>, L7>, std::tuple<char, double>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<X>, L7>, X<char, double>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<Y>, L7>, Y<char, double>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<std::pair>, L7>, std::pair<char, double>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<Q, L7>, X<char, double>>));
|
||||||
|
|
||||||
|
using L8 = std::tuple<int, char, float>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<mp_list>, L8>, mp_list<int, char, float>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<std::tuple>, L8>, std::tuple<int, char, float>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<X>, L8>, X<int, char, float>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<Y>, L8>, Y<int, char, float>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<Q, L8>, X<int, char, float>>));
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
using L9 = std::pair<char, double>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<mp_list>, L9>, mp_list<char, double>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<std::tuple>, L9>, std::tuple<char, double>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<X>, L9>, X<char, double>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<Y>, L9>, Y<char, double>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<mp_quote<std::pair>, L9>, std::pair<char, double>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_apply_q<Q, L9>, X<char, double>>));
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user