forked from boostorg/mp11
Merge branch 'develop'
This commit is contained in:
@@ -157,6 +157,14 @@
|
||||
<dt><span class="section"><a href="mp11.html#mp11.reference.function.mp_or_t"><code class="computeroutput"><span class="identifier">mp_or</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.function.mp_any_t"><code class="computeroutput"><span class="identifier">mp_any</span><span class="special"><</span><span class="identifier">T</span><span class="special">...></span></code></a></span></dt>
|
||||
</dl></dd>
|
||||
<dt><span class="section"><a href="mp11.html#mp11.reference.bind">Bind, <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">mp11</span><span class="special">/</span><span class="identifier">bind</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="mp11.html#mp11.reference.bind.mp_arg_i"><code class="computeroutput"><span class="identifier">mp_arg</span><span class="special"><</span><span class="identifier">I</span><span class="special">></span></code></a></span></dt>
|
||||
<dt><span class="section"><a href="mp11.html#mp11.reference.bind.1_9"><code class="computeroutput"><span class="identifier">_1</span></code>,
|
||||
..., <code class="computeroutput"><span class="identifier">_9</span></code></a></span></dt>
|
||||
<dt><span class="section"><a href="mp11.html#mp11.reference.bind.mp_bind_f_t"><code class="computeroutput"><span class="identifier">mp_bind</span><span class="special"><</span><span class="identifier">F</span><span class="special">,</span>
|
||||
<span class="identifier">T</span><span class="special">...></span></code></a></span></dt>
|
||||
</dl></dd>
|
||||
<dt><span class="section"><a href="mp11.html#mp11.reference.integer_sequence">Integer Sequences,
|
||||
<code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer_sequence</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
|
||||
<dd><dl>
|
||||
@@ -215,7 +223,7 @@
|
||||
<a name="mp11.definitions"></a><a class="link" href="mp11.html#mp11.definitions" title="Definitions">Definitions</a>
|
||||
</h2></div></div></div>
|
||||
<p>
|
||||
A <span class="emphasis"><em>list</em></span> is a — possibly but not necessarily variadic — template
|
||||
A <span class="emphasis"><em>list</em></span> is a — usually but not necessarily variadic — template
|
||||
class whose parameters are all types, for example <code class="computeroutput"><span class="identifier">mp_list</span><span class="special"><</span><span class="keyword">char</span><span class="special">[],</span>
|
||||
<span class="keyword">void</span><span class="special">></span></code>,
|
||||
<code class="computeroutput"><span class="identifier">mp_list</span><span class="special"><></span></code>,
|
||||
@@ -251,6 +259,16 @@
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">N</span> <span class="special">{</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="keyword">constexpr</span> <span class="identifier">value</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span> <span class="special">};</span>
|
||||
</pre>
|
||||
<p>
|
||||
A <span class="emphasis"><em>set</em></span> is a list whose elements are unique.
|
||||
</p>
|
||||
<p>
|
||||
A <span class="emphasis"><em>map</em></span> is a list of lists, the inner lists having at least
|
||||
one element (the key.) The keys of the map must be unique. For example,
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">M1</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">*>,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">float</span><span class="special">,</span> <span class="keyword">float</span><span class="special">*>,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">void</span><span class="special">,</span> <span class="keyword">void</span><span class="special">*>>;</span>
|
||||
<span class="keyword">using</span> <span class="identifier">M2</span> <span class="special">=</span> <span class="identifier">mp_list</span><span class="special"><</span><span class="identifier">mp_list</span><span class="special"><</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">*>,</span> <span class="identifier">mp_list</span><span class="special"><</span><span class="keyword">float</span><span class="special">>,</span> <span class="identifier">mp_list</span><span class="special"><</span><span class="keyword">char</span><span class="special">,</span> <span class="keyword">char</span><span class="special">[</span><span class="number">1</span><span class="special">],</span> <span class="keyword">char</span><span class="special">[</span><span class="number">2</span><span class="special">]>>;</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
@@ -1609,6 +1627,62 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="mp11.reference.bind"></a><a class="link" href="mp11.html#mp11.reference.bind" title="Bind, <boost/mp11/bind.hpp>">Bind, <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">mp11</span><span class="special">/</span><span class="identifier">bind</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a>
|
||||
</h3></div></div></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="mp11.reference.bind.mp_arg_i"></a><a class="link" href="mp11.html#mp11.reference.bind.mp_arg_i" title="mp_arg<I>"><code class="computeroutput"><span class="identifier">mp_arg</span><span class="special"><</span><span class="identifier">I</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="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">I</span><span class="special">></span> <span class="keyword">struct</span> <span class="identifier">mp_arg</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">mp_arg</span><span class="special"><</span><span class="identifier">I</span><span class="special">></span></code>
|
||||
is a quoted metafunction whose nested template <code class="computeroutput"><span class="identifier">fn</span><span class="special"><</span><span class="identifier">T</span><span class="special">...></span></code> returns the <code class="computeroutput"><span class="identifier">I</span></code>-th
|
||||
zero-based element of <code class="computeroutput"><span class="identifier">T</span><span class="special">...</span></code>.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="mp11.reference.bind.1_9"></a><a class="link" href="mp11.html#mp11.reference.bind.1_9" title="_1, ..., _9"><code class="computeroutput"><span class="identifier">_1</span></code>,
|
||||
..., <code class="computeroutput"><span class="identifier">_9</span></code></a>
|
||||
</h4></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">_1</span> <span class="special">=</span> <span class="identifier">mp_arg</span><span class="special"><</span><span class="number">0</span><span class="special">>;</span>
|
||||
<span class="keyword">using</span> <span class="identifier">_2</span> <span class="special">=</span> <span class="identifier">mp_arg</span><span class="special"><</span><span class="number">1</span><span class="special">>;</span>
|
||||
<span class="keyword">using</span> <span class="identifier">_3</span> <span class="special">=</span> <span class="identifier">mp_arg</span><span class="special"><</span><span class="number">2</span><span class="special">>;</span>
|
||||
<span class="keyword">using</span> <span class="identifier">_4</span> <span class="special">=</span> <span class="identifier">mp_arg</span><span class="special"><</span><span class="number">3</span><span class="special">>;</span>
|
||||
<span class="keyword">using</span> <span class="identifier">_5</span> <span class="special">=</span> <span class="identifier">mp_arg</span><span class="special"><</span><span class="number">4</span><span class="special">>;</span>
|
||||
<span class="keyword">using</span> <span class="identifier">_6</span> <span class="special">=</span> <span class="identifier">mp_arg</span><span class="special"><</span><span class="number">5</span><span class="special">>;</span>
|
||||
<span class="keyword">using</span> <span class="identifier">_7</span> <span class="special">=</span> <span class="identifier">mp_arg</span><span class="special"><</span><span class="number">6</span><span class="special">>;</span>
|
||||
<span class="keyword">using</span> <span class="identifier">_8</span> <span class="special">=</span> <span class="identifier">mp_arg</span><span class="special"><</span><span class="number">7</span><span class="special">>;</span>
|
||||
<span class="keyword">using</span> <span class="identifier">_9</span> <span class="special">=</span> <span class="identifier">mp_arg</span><span class="special"><</span><span class="number">8</span><span class="special">>;</span>
|
||||
</pre>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">_1</span></code> to <code class="computeroutput"><span class="identifier">_9</span></code>
|
||||
are placeholder types, the equivalent to the placeholders of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span></code>.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="mp11.reference.bind.mp_bind_f_t"></a><a class="link" href="mp11.html#mp11.reference.bind.mp_bind_f_t" title="mp_bind<F, T...>"><code class="computeroutput"><span class="identifier">mp_bind</span><span class="special"><</span><span class="identifier">F</span><span class="special">,</span>
|
||||
<span class="identifier">T</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">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="special">...</span> <span class="identifier">T</span><span class="special">></span> <span class="keyword">struct</span> <span class="identifier">mp_bind</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">mp_bind</span><span class="special"><</span><span class="identifier">F</span><span class="special">,</span> <span class="identifier">T</span><span class="special">...></span></code> is a quoted metafunction that implements
|
||||
the type-based equivalent of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span></code>.
|
||||
Its nested template <code class="computeroutput"><span class="identifier">fn</span><span class="special"><</span><span class="identifier">U</span><span class="special">...></span></code> returns <code class="computeroutput"><span class="identifier">F</span><span class="special"><</span><span class="identifier">V</span><span class="special">...></span></code>, where <code class="computeroutput"><span class="identifier">V</span><span class="special">...</span></code> is <code class="computeroutput"><span class="identifier">T</span><span class="special">...</span></code> with the placeholders replaced by the
|
||||
corresponding element of <code class="computeroutput"><span class="identifier">U</span><span class="special">...</span></code> and the <code class="computeroutput"><span class="identifier">mp_bind</span></code>
|
||||
expressions replaced with their corresponding evaluations against <code class="computeroutput"><span class="identifier">U</span><span class="special">...</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
For example, <code class="computeroutput"><span class="identifier">mp_bind</span><span class="special"><</span><span class="identifier">F</span><span class="special">,</span> <span class="keyword">int</span><span class="special">,</span> <span class="identifier">_2</span><span class="special">,</span> <span class="identifier">mp_bind</span><span class="special"><</span><span class="identifier">G</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">>>::</span><span class="identifier">fn</span><span class="special"><</span><span class="keyword">float</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span></code>
|
||||
is <code class="computeroutput"><span class="identifier">F</span><span class="special"><</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">void</span><span class="special">,</span> <span class="identifier">G</span><span class="special"><</span><span class="keyword">float</span><span class="special">>></span></code>.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="mp11.reference.integer_sequence"></a><a class="link" href="mp11.html#mp11.reference.integer_sequence" title="Integer Sequences, <boost/integer_sequence.hpp>">Integer Sequences,
|
||||
<code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer_sequence</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a>
|
||||
</h3></div></div></div>
|
||||
@@ -1706,7 +1780,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: March 25, 2017 at 01:01:08 GMT</small></p></td>
|
||||
<td align="left"><p><small>Last revised: April 01, 2017 at 16:43:16 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
@@ -38,6 +38,7 @@ The contents of the library are in namespace `boost::mp11`, unless specified oth
|
||||
[include mp11/set.qbk]
|
||||
[include mp11/map.qbk]
|
||||
[include mp11/function.qbk]
|
||||
[include mp11/bind.qbk]
|
||||
[include mp11/integer_sequence.qbk]
|
||||
[include mp11/tuple_for_each.qbk]
|
||||
|
||||
|
41
doc/mp11/bind.qbk
Normal file
41
doc/mp11/bind.qbk
Normal file
@@ -0,0 +1,41 @@
|
||||
[/
|
||||
/ Copyright 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)
|
||||
/]
|
||||
|
||||
[section:bind Bind, `<boost/mp11/bind.hpp>`]
|
||||
|
||||
[section `mp_arg<I>`]
|
||||
template<std::size_t I> struct mp_arg;
|
||||
|
||||
`mp_arg<I>` is a quoted metafunction whose nested template `fn<T...>` returns the `I`-th zero-based element of `T...`.
|
||||
[endsect]
|
||||
|
||||
[section `_1`, ..., `_9`]
|
||||
using _1 = mp_arg<0>;
|
||||
using _2 = mp_arg<1>;
|
||||
using _3 = mp_arg<2>;
|
||||
using _4 = mp_arg<3>;
|
||||
using _5 = mp_arg<4>;
|
||||
using _6 = mp_arg<5>;
|
||||
using _7 = mp_arg<6>;
|
||||
using _8 = mp_arg<7>;
|
||||
using _9 = mp_arg<8>;
|
||||
|
||||
`_1` to `_9` are placeholder types, the equivalent to the placeholders of `boost::bind`.
|
||||
[endsect]
|
||||
|
||||
[section `mp_bind<F, T...>`]
|
||||
template<template<class...> class F, class... T> struct mp_bind;
|
||||
|
||||
`mp_bind<F, T...>` is a quoted metafunction that implements the type-based equivalent of `boost::bind`. Its nested
|
||||
template `fn<U...>` returns `F<V...>`, where `V...` is `T...` with the placeholders replaced by the corresponding element
|
||||
of `U...` and the `mp_bind` expressions replaced with their corresponding evaluations against `U...`.
|
||||
|
||||
For example, `mp_bind<F, int, _2, mp_bind<G, _1>>::fn<float, void>` is `F<int, void, G<float>>`.
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
@@ -8,7 +8,7 @@
|
||||
|
||||
[section Definitions]
|
||||
|
||||
A /list/ is a '''—''' possibly but not necessarily variadic '''—''' template class whose parameters are all types,
|
||||
A /list/ is a '''—''' usually but not necessarily variadic '''—''' template class whose parameters are all types,
|
||||
for example `mp_list<char[], void>`, `mp_list<>`, `std::tuple<int, float, char>`, `std::pair<int, float>`, `std::shared_ptr<X>`.
|
||||
|
||||
A /metafunction/ is a class template or a template alias whose parameters are all types, for example `std::add_pointer_t`,
|
||||
@@ -29,4 +29,11 @@ An /integral constant type/ is a class with a public member `value` that is an i
|
||||
|
||||
struct N { static int constexpr value = 2; };
|
||||
|
||||
A /set/ is a list whose elements are unique.
|
||||
|
||||
A /map/ is a list of lists, the inner lists having at least one element (the key.) The keys of the map must be unique. For example,
|
||||
|
||||
using M1 = std::tuple<std::pair<int, int*>, std::pair<float, float*>, std::pair<void, void*>>;
|
||||
using M2 = mp_list<mp_list<int, int*>, mp_list<float>, mp_list<char, char[1], char[2]>>;
|
||||
|
||||
[endsect]
|
||||
|
@@ -15,5 +15,6 @@
|
||||
#include <boost/mp11/function.hpp>
|
||||
#include <boost/mp11/map.hpp>
|
||||
#include <boost/mp11/set.hpp>
|
||||
#include <boost/mp11/bind.hpp>
|
||||
|
||||
#endif // #ifndef BOOST_MP11_HPP_INCLUDED
|
||||
|
@@ -44,6 +44,16 @@ template<class L1, class L2> using mp_assign = typename detail::mp_assign_impl<L
|
||||
// mp_clear<L>
|
||||
template<class L> using mp_clear = mp_assign<L, mp_list<>>;
|
||||
|
||||
// mp_fold<L, V, F> forward declaration
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class L, class V, template<class...> class F> struct mp_fold_impl;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class L, class V, template<class...> class F> using mp_fold = typename detail::mp_fold_impl<L, V, F>::type;
|
||||
|
||||
// mp_transform<F, L...>
|
||||
namespace detail
|
||||
{
|
||||
@@ -71,69 +81,46 @@ template<template<class...> class F, template<class...> class L1, class... T1, t
|
||||
|
||||
template<template<class...> class F, class... L> using mp_transform = typename detail::mp_transform_impl<F, L...>::type;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<template<class...> class F, template<class...> class L1, class... T1, template<class...> class L2, class... T2, template<class...> class L3, class... T3, template<class...> class L4, class... T4, class... L> struct mp_transform_impl<F, L1<T1...>, L2<T2...>, L3<T3...>, L4<T4...>, L...>
|
||||
{
|
||||
static_assert( sizeof...(T1) == sizeof...(T2) && sizeof...(T1) == sizeof...(T3) && sizeof...(T1) == sizeof...(T4), "The arguments of mp_transform should be of the same size" );
|
||||
|
||||
using A1 = L1<mp_list<T1, T2, T3, T4>...>;
|
||||
|
||||
template<class V, class T> using _f = mp_transform<mp_push_back, V, T>;
|
||||
|
||||
using A2 = mp_fold<mp_list<L...>, A1, _f>;
|
||||
|
||||
template<class T> using _g = mp_apply<F, T>;
|
||||
|
||||
using type = mp_transform<_g, A2>;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// mp_transform_if<P, F, L...>
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/*
|
||||
template<template<class...> class P, template<class...> class F, class... L> struct mp_transform_if_impl
|
||||
{
|
||||
// error: pack expansion used as argument for non-pack parameter of alias template
|
||||
template<class... U> using _f = mp_eval_if<mp_not<P<U...>>, mp_first<mp_list<U...>>, F, U...>;
|
||||
// the stupid quote-unquote dance avoids "pack expansion used as argument for non-pack parameter of alias template"
|
||||
#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> 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...>;
|
||||
|
||||
#endif
|
||||
|
||||
using type = mp_transform<_f, L...>;
|
||||
};
|
||||
*/
|
||||
|
||||
template<template<class...> class P, template<class...> class F, class... L> struct mp_transform_if_impl;
|
||||
|
||||
template<template<class...> class P, template<class...> class F, template<class...> class L, class... T> struct mp_transform_if_impl<P, F, L<T...>>
|
||||
{
|
||||
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1910 )
|
||||
|
||||
template<class U> struct _f { using type = mp_eval_if<mp_not<P<U>>, U, F, U>; };
|
||||
using type = L<typename _f<T>::type...>;
|
||||
|
||||
#else
|
||||
|
||||
template<class U> using _f = mp_eval_if<mp_not<P<U>>, U, F, U>;
|
||||
using type = L<_f<T>...>;
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
template<template<class...> class P, template<class...> class F, template<class...> class L1, class... T1, template<class...> class L2, class... T2> struct mp_transform_if_impl<P, F, L1<T1...>, L2<T2...>>
|
||||
{
|
||||
static_assert( sizeof...(T1) == sizeof...(T2), "The arguments of mp_transform_if should be of the same size" );
|
||||
|
||||
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1910 )
|
||||
|
||||
template<class U1, class U2> struct _f { using type = mp_eval_if<mp_not<P<U1, U2>>, U1, F, U1, U2>; };
|
||||
using type = L1<typename _f<T1, T2>::type...>;
|
||||
|
||||
#else
|
||||
|
||||
template<class U1, class U2> using _f = mp_eval_if<mp_not<P<U1, U2>>, U1, F, U1, U2>;
|
||||
using type = L1<_f<T1, T2>...>;
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
template<template<class...> class P, template<class...> class F, template<class...> class L1, class... T1, template<class...> class L2, class... T2, template<class...> class L3, class... T3> struct mp_transform_if_impl<P, F, L1<T1...>, L2<T2...>, L3<T3...>>
|
||||
{
|
||||
static_assert( sizeof...(T1) == sizeof...(T2) && sizeof...(T1) == sizeof...(T3), "The arguments of mp_transform_if should be of the same size" );
|
||||
|
||||
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1910 )
|
||||
|
||||
template<class U1, class U2, class U3> struct _f { using type = mp_eval_if<mp_not<P<U1, U2, U3>>, U1, F, U1, U2, U3>; };
|
||||
using type = L1<typename _f<T1, T2, T3>::type...>;
|
||||
|
||||
#else
|
||||
|
||||
template<class U1, class U2, class U3> using _f = mp_eval_if<mp_not<P<U1, U2, U3>>, U1, F, U1, U2, U3>;
|
||||
using type = L1<_f<T1, T2, T3>...>;
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
@@ -753,8 +740,6 @@ template<template<class...> class L, class T1, class T2, class T3, class T4, cla
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class L, class V, template<class...> class F> using mp_fold = typename detail::mp_fold_impl<L, V, F>::type;
|
||||
|
||||
// mp_reverse_fold<L, V, F>
|
||||
namespace detail
|
||||
{
|
||||
|
64
include/boost/mp11/bind.hpp
Normal file
64
include/boost/mp11/bind.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef BOOST_MP11_BIND_HPP_INCLUDED
|
||||
#define BOOST_MP11_BIND_HPP_INCLUDED
|
||||
|
||||
// Copyright 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 <cstddef>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace mp11
|
||||
{
|
||||
|
||||
template<std::size_t I> struct mp_arg
|
||||
{
|
||||
template<class... T> using fn = mp_at_c<mp_list<T...>, I>;
|
||||
};
|
||||
|
||||
using _1 = mp_arg<0>;
|
||||
using _2 = mp_arg<1>;
|
||||
using _3 = mp_arg<2>;
|
||||
using _4 = mp_arg<3>;
|
||||
using _5 = mp_arg<4>;
|
||||
using _6 = mp_arg<5>;
|
||||
using _7 = mp_arg<6>;
|
||||
using _8 = mp_arg<7>;
|
||||
using _9 = mp_arg<8>;
|
||||
|
||||
template<template<class...> class F, class... T> struct mp_bind;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class V, class... T> struct eval_bound_arg
|
||||
{
|
||||
using type = V;
|
||||
};
|
||||
|
||||
template<std::size_t I, class... T> struct eval_bound_arg<mp_arg<I>, T...>
|
||||
{
|
||||
using type = typename mp_arg<I>::template fn<T...>;
|
||||
};
|
||||
|
||||
template<template<class...> class F, class... U, class... T> struct eval_bound_arg<mp_bind<F, U...>, T...>
|
||||
{
|
||||
using type = typename mp_bind<F, U...>::template fn<T...>;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<template<class...> class F, class... T> struct mp_bind
|
||||
{
|
||||
template<class... U> using fn = F<typename detail::eval_bound_arg<T, U...>::type...>;
|
||||
};
|
||||
|
||||
} // namespace mp11
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_MP11_BIND_HPP_INCLUDED
|
@@ -12,6 +12,7 @@
|
||||
#include <boost/mp11/utility.hpp>
|
||||
#include <boost/mp11/detail/mp_list.hpp>
|
||||
#include <boost/mp11/detail/mp_count.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@@ -84,6 +85,26 @@ template<class T1, class... T> struct mp_or_impl<T1, T...>
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// mp_same<T...>
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class... T> struct mp_same_impl;
|
||||
|
||||
template<> struct mp_same_impl<>
|
||||
{
|
||||
using type = mp_true;
|
||||
};
|
||||
|
||||
template<class T1, class... T> struct mp_same_impl<T1, T...>
|
||||
{
|
||||
using type = mp_all<std::is_same<T1, T>...>;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class... T> using mp_same = typename detail::mp_same_impl<T...>::type;
|
||||
|
||||
} // namespace mp11
|
||||
} // namespace boost
|
||||
|
||||
|
@@ -94,6 +94,7 @@ run mp_all.cpp : : : $(REQ) ;
|
||||
run mp_and.cpp : : : $(REQ) ;
|
||||
run mp_any.cpp : : : $(REQ) ;
|
||||
run mp_or.cpp : : : $(REQ) ;
|
||||
run mp_same.cpp : : : $(REQ) ;
|
||||
|
||||
# map
|
||||
run mp_map_find.cpp : : : $(REQ) ;
|
||||
@@ -102,3 +103,6 @@ run mp_map_insert.cpp : : : $(REQ) ;
|
||||
run mp_map_replace.cpp : : : $(REQ) ;
|
||||
run mp_map_erase.cpp : : : $(REQ) ;
|
||||
run mp_map_update.cpp : : : $(REQ) ;
|
||||
|
||||
# bind
|
||||
run mp_bind.cpp : : : $(REQ) ;
|
||||
|
106
test/mp_bind.cpp
Normal file
106
test/mp_bind.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
|
||||
// Copyright 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/bind.hpp>
|
||||
#include <boost/mp11/list.hpp>
|
||||
#include <boost/mp11/algorithm.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
struct X1 {};
|
||||
struct X2 {};
|
||||
struct X3 {};
|
||||
struct X4 {};
|
||||
struct X5 {};
|
||||
struct X6 {};
|
||||
struct X7 {};
|
||||
struct X8 {};
|
||||
struct X9 {};
|
||||
|
||||
template<class T> using add_pointer = typename std::add_pointer<T>::type;
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost::mp11;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_1::fn<X1>, X1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_1::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X1>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_2::fn<X1, X2>, X2>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_2::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X2>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_3::fn<X1, X2, X3>, X3>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_3::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X3>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_4::fn<X1, X2, X3, X4>, X4>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_4::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X4>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_5::fn<X1, X2, X3, X4, X5>, X5>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_5::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X5>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_6::fn<X1, X2, X3, X4, X5, X6>, X6>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_6::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X6>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_7::fn<X1, X2, X3, X4, X5, X6, X7>, X7>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_7::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X7>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_8::fn<X1, X2, X3, X4, X5, X6, X7, X8>, X8>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_8::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X8>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<_9::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X9>));
|
||||
|
||||
//
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _1>::fn<X1>, X1*>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _1>::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X1*>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _2>::fn<X1, X2>, X2*>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _2>::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X2*>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _3>::fn<X1, X2, X3>, X3*>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _3>::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X3*>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _4>::fn<X1, X2, X3, X4>, X4*>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _4>::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X4*>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _5>::fn<X1, X2, X3, X4, X5>, X5*>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _5>::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X5*>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _6>::fn<X1, X2, X3, X4, X5, X6>, X6*>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _6>::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X6*>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _7>::fn<X1, X2, X3, X4, X5, X6, X7>, X7*>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _7>::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X7*>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _8>::fn<X1, X2, X3, X4, X5, X6, X7, X8>, X8*>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _8>::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X8*>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bind<add_pointer, _9>::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, X9*>));
|
||||
|
||||
//
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<
|
||||
mp_bind<std::tuple,
|
||||
mp_bind<add_pointer, _9>,
|
||||
mp_bind<add_pointer, _8>,
|
||||
mp_bind<add_pointer, _7>,
|
||||
mp_bind<add_pointer, _6>,
|
||||
mp_bind<add_pointer, _5>,
|
||||
mp_bind<add_pointer, _4>,
|
||||
mp_bind<add_pointer, _3>,
|
||||
mp_bind<add_pointer, _2>,
|
||||
mp_bind<add_pointer, _1>
|
||||
>::fn<X1, X2, X3, X4, X5, X6, X7, X8, X9>, std::tuple<X9*, X8*, X7*, X6*, X5*, X4*, X3*, X2*, X1*>>));
|
||||
|
||||
//
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
33
test/mp_same.cpp
Normal file
33
test/mp_same.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
// Copyright 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/function.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp11::mp_same;
|
||||
using boost::mp11::mp_true;
|
||||
using boost::mp11::mp_false;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_same<>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_same<void>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_same<void, void>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_same<void, void, void>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_same<void, void, void, void>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_same<void, void, void, void, void>, mp_true>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_same<void, int>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_same<void, void, int>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_same<void, void, void, int>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_same<void, void, void, void, int>, mp_false>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@@ -29,6 +29,15 @@ struct Z2 {};
|
||||
struct Z3 {};
|
||||
struct Z4 {};
|
||||
|
||||
struct U1 {};
|
||||
struct U2 {};
|
||||
|
||||
struct V1 {};
|
||||
struct V2 {};
|
||||
|
||||
struct W1 {};
|
||||
struct W2 {};
|
||||
|
||||
template<class T> using add_pointer = typename std::add_pointer<T>::type;
|
||||
template<class T, class U> using is_same = typename std::is_same<T, U>::type;
|
||||
|
||||
@@ -81,5 +90,16 @@ int main()
|
||||
|
||||
//
|
||||
|
||||
using L8 = std::pair<Z1, Z2>;
|
||||
using L9 = std::pair<U1, U2>;
|
||||
using L10 = std::pair<V1, V2>;
|
||||
using L11 = std::pair<W1, W2>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<std::tuple, L5, L6, L8, L9>, std::pair<std::tuple<X1, Y1, Z1, U1>, std::tuple<X2, Y2, Z2, U2>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<std::tuple, L5, L6, L8, L9, L10>, std::pair<std::tuple<X1, Y1, Z1, U1, V1>, std::tuple<X2, Y2, Z2, U2, V2>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<std::tuple, L5, L6, L8, L9, L10, L11>, std::pair<std::tuple<X1, Y1, Z1, U1, V1, W1>, std::tuple<X2, Y2, Z2, U2, V2, W2>>>));
|
||||
|
||||
//
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@@ -26,6 +26,8 @@ template<class T> using add_pointer = T*;
|
||||
template<class T, class...> using is_not_ref = mp_not<std::is_reference<T>>;
|
||||
template<class T1, class T2> using second = T2;
|
||||
template<class T1, class T2, class T3> using third = T3;
|
||||
template<class T1, class T2, class T3, class T4> using fourth = T4;
|
||||
template<class T1, class T2, class T3, class T4, class T5> using fifth = T5;
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -58,6 +60,14 @@ int main()
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, 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<is_not_ref, 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<is_not_ref, 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<is_not_ref, 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<is_not_ref, 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<is_not_ref, 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<is_not_ref, 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<is_not_ref, 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