forked from boostorg/mp11
Add mp_transform_if_q
This commit is contained in:
@@ -107,6 +107,7 @@
|
||||
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_transform_f_l"><code class="computeroutput"><span class="identifier">mp_transform</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>
|
||||
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_transform_q_q_l"><code class="computeroutput"><span class="identifier">mp_transform_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.algorithm.mp_transform_if_p_f_l"><code class="computeroutput"><span class="identifier">mp_transform_if</span><span class="special"><</span><span class="identifier">P</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>
|
||||
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_transform_if_q_qp_qf_l"><code class="computeroutput"><span class="identifier">mp_transform_if_q</span><span class="special"><</span><span class="identifier">Qp</span><span class="special">,</span> <span class="identifier">Qf</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.algorithm.mp_fill_l_v"><code class="computeroutput"><span class="identifier">mp_fill</span><span class="special"><</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">V</span><span class="special">></span></code></a></span></dt>
|
||||
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_count_l_v"><code class="computeroutput"><span class="identifier">mp_count</span><span class="special"><</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">V</span><span class="special">></span></code></a></span></dt>
|
||||
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_count_if_l_p"><code class="computeroutput"><span class="identifier">mp_count_if</span><span class="special"><</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">P</span><span class="special">></span></code></a></span></dt>
|
||||
@@ -1526,6 +1527,17 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="mp11.reference.algorithm.mp_transform_if_q_qp_qf_l"></a><a class="link" href="mp11.html#mp11.reference.algorithm.mp_transform_if_q_qp_qf_l" title="mp_transform_if_q<Qp, Qf, L...>"><code class="computeroutput"><span class="identifier">mp_transform_if_q</span><span class="special"><</span><span class="identifier">Qp</span><span class="special">,</span> <span class="identifier">Qf</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">Qp</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Qf</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_transform_if_q</span> <span class="special">=</span> <span class="identifier">mp_transform_if</span><span class="special"><</span><span class="identifier">Qp</span><span class="special">::</span><span class="keyword">template</span> <span class="identifier">fn</span><span class="special">,</span> <span class="identifier">Qf</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>
|
||||
As <code class="computeroutput"><span class="identifier">mp_transform_if</span></code>, but
|
||||
takes a quoted metafunction.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="mp11.reference.algorithm.mp_fill_l_v"></a><a class="link" href="mp11.html#mp11.reference.algorithm.mp_fill_l_v" title="mp_fill<L, V>"><code class="computeroutput"><span class="identifier">mp_fill</span><span class="special"><</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">V</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">L</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span> <span class="keyword">using</span> <span class="identifier">mp_fill</span> <span class="special">=</span> <span class="comment">/*...*/</span><span class="special">;</span>
|
||||
@@ -2492,7 +2504,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"><p><small>Last revised: May 24, 2017 at 17:55:07 GMT</small></p></td>
|
||||
<td align="left"><p><small>Last revised: May 25, 2017 at 18:29:52 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
@@ -39,6 +39,12 @@ As `mp_transform`, but takes a quoted metafunction.
|
||||
`F<T1, T2, ..., Tn>`, and returns the result, where `Ti` are the corresponding elements of `Li`.
|
||||
[endsect]
|
||||
|
||||
[section `mp_transform_if_q<Qp, Qf, L...>`]
|
||||
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.
|
||||
[endsect]
|
||||
|
||||
[section `mp_fill<L, V>`]
|
||||
template<class L, class V> using mp_fill = /*...*/;
|
||||
|
||||
|
@@ -125,14 +125,18 @@ namespace detail
|
||||
template<template<class...> class P, template<class...> 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<P>;
|
||||
using Qf = mp_quote<F>;
|
||||
|
||||
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1910 )
|
||||
|
||||
template<class... U> struct _f_ { using type = mp_eval_if<mp_not<mp_invoke<mp_quote<P>, U...>>, mp_first<mp_list<U...>>, mp_quote<F>::template fn, U...>; };
|
||||
template<class... U> struct _f_ { using type = mp_eval_if_q<mp_not<mp_invoke<Qp, U...>>, mp_first<mp_list<U...>>, Qf, U...>; };
|
||||
template<class... U> using _f = typename _f_<U...>::type;
|
||||
|
||||
#else
|
||||
|
||||
template<class... U> using _f = mp_eval_if<mp_not<mp_invoke<mp_quote<P>, U...>>, mp_first<mp_list<U...>>, mp_quote<F>::template fn, U...>;
|
||||
template<class... U> using _f = mp_eval_if_q<mp_not<mp_invoke<Qp, U...>>, mp_first<mp_list<U...>>, Qf, U...>;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -142,6 +146,7 @@ template<template<class...> class P, template<class...> class F, class... L> str
|
||||
} // namespace detail
|
||||
|
||||
template<template<class...> class P, template<class...> class F, class... L> using mp_transform_if = typename detail::mp_transform_if_impl<P, F, L...>::type;
|
||||
template<class Qp, class Qf, class... L> using mp_transform_if_q = typename detail::mp_transform_if_impl<Qp::template fn, Qf::template fn, L...>::type;
|
||||
|
||||
// mp_fill<L, V>
|
||||
namespace detail
|
||||
|
@@ -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) ;
|
||||
|
87
test/mp_transform_if_q.cpp
Normal file
87
test/mp_transform_if_q.cpp
Normal file
@@ -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 <boost/mp11/algorithm.hpp>
|
||||
#include <boost/mp11/list.hpp>
|
||||
#include <boost/mp11/integral.hpp>
|
||||
#include <boost/mp11/utility.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
struct X1 {};
|
||||
struct X2 {};
|
||||
struct X3 {};
|
||||
struct X4 {};
|
||||
|
||||
using boost::mp11::mp_not;
|
||||
using boost::mp11::mp_quote;
|
||||
|
||||
template<class T> using add_pointer = T*;
|
||||
using Q_add_pointer = mp_quote<add_pointer>;
|
||||
|
||||
template<class T, class...> using is_not_ref = mp_not<std::is_reference<T>>;
|
||||
using Q_is_not_ref = mp_quote<is_not_ref>;
|
||||
|
||||
template<class T1, class T2> using second = T2;
|
||||
using Q_second = mp_quote<second>;
|
||||
|
||||
template<class T1, class T2, class T3> using third = T3;
|
||||
using Q_third = mp_quote<third>;
|
||||
|
||||
template<class T1, class T2, class T3, class T4> using fourth = T4;
|
||||
using Q_fourth = mp_quote<fourth>;
|
||||
|
||||
template<class T1, class T2, class T3, class T4, class T5> using fifth = T5;
|
||||
using Q_fifth = mp_quote<fifth>;
|
||||
|
||||
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<X1, X2&, X3 const, X4 const&>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if_q<Q_is_not_ref, Q_add_pointer, L1>, mp_list<X1*, X2&, X3 const*, X4 const&>>));
|
||||
|
||||
using L2 = std::tuple<X1, X2&, X3 const, X4 const&>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if_q<Q_is_not_ref, Q_add_pointer, L2>, std::tuple<X1*, X2&, X3 const*, X4 const&>>));
|
||||
|
||||
using L3 = std::pair<X1 const, X2&>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if_q<Q_is_not_ref, Q_add_pointer, L3>, std::pair<X1 const*, X2&>>));
|
||||
|
||||
//
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if_q<Q_is_not_ref, Q_second, L1, mp_fill<L1, void>>, mp_list<void, X2&, void, X4 const&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if_q<Q_is_not_ref, Q_second, L2, mp_fill<L2, void>>, std::tuple<void, X2&, void, X4 const&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if_q<Q_is_not_ref, Q_second, L3, mp_fill<L3, void>>, std::pair<void, X2&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if_q<Q_is_not_ref, Q_third, L1, L1, mp_iota<mp_size<L1>>>, mp_list<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if_q<Q_is_not_ref, Q_third, L2, L2, mp_iota<mp_size<L2>>>, std::tuple<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if_q<Q_is_not_ref, Q_third, L3, L3, mp_iota<mp_size<L3>>>, std::pair<mp_size_t<0>, X2&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if_q<Q_is_not_ref, Q_fourth, L1, L1, L1, mp_iota<mp_size<L1>>>, mp_list<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if_q<Q_is_not_ref, Q_fourth, L2, L2, L2, mp_iota<mp_size<L2>>>, std::tuple<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if_q<Q_is_not_ref, Q_fourth, L3, L3, L3, mp_iota<mp_size<L3>>>, std::pair<mp_size_t<0>, X2&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if_q<Q_is_not_ref, Q_fifth, L1, L1, L1, L1, mp_iota<mp_size<L1>>>, mp_list<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if_q<Q_is_not_ref, Q_fifth, L2, L2, L2, L2, mp_iota<mp_size<L2>>>, std::tuple<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if_q<Q_is_not_ref, Q_fifth, L3, L3, L3, L3, mp_iota<mp_size<L3>>>, std::pair<mp_size_t<0>, X2&>>));
|
||||
|
||||
//
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user