forked from boostorg/mp11
Document mp_quote_trait
This commit is contained in:
@@ -487,6 +487,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
|
||||
<li><a href="#mp_valid_f_t">mp_valid<F, T…​></a></li>
|
||||
<li><a href="#mp_defer_f_t">mp_defer<F, T…​></a></li>
|
||||
<li><a href="#mp_quote_f">mp_quote<F></a></li>
|
||||
<li><a href="#mp_quote_trait_f">mp_quote_trait<F></a></li>
|
||||
<li><a href="#mp_invoke_q_t">mp_invoke<Q, T…​></a></li>
|
||||
</ul>
|
||||
</li>
|
||||
@@ -2028,6 +2029,28 @@ template<class T> struct has_nested_type: mp_valid<get_nested_type, T&g
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="mp_quote_trait_f">mp_quote_trait<F></h4>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre>template<template<class...> class F> struct mp_quote_trait
|
||||
{
|
||||
template<class... T> using fn = typename F<T...>::type;
|
||||
};</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p><code>mp_quote_trait<F></code> transforms the C++03-style trait <code>F</code> into a quoted metafunction.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 42. Using mp_quote_trait with std::add_pointer</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using L1 = mp_list<int, void, float>;
|
||||
using R1 = mp_transform_q<mp_quote_trait<std::add_pointer>, L1>;
|
||||
// mp_list<int*, void*, float*></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="mp_invoke_q_t">mp_invoke<Q, T…​></h4>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
@@ -2038,7 +2061,7 @@ template<class T> struct has_nested_type: mp_valid<get_nested_type, T&g
|
||||
<p><code>mp_invoke<Q, T…​></code> evaluates the nested template <code>fn</code> of a quoted metafunction. <code>mp_invoke<mp_quote<F>, T…​></code> returns <code>F<T…​></code>.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 42. Using mp_invoke to invoke a list of metafunctions, technique 1</div>
|
||||
<div class="title">Code Example 43. Using mp_invoke to invoke a list of metafunctions, technique 1</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using LQ = mp_list<mp_quote<std::is_const>, mp_quote<std::is_volatile>>;
|
||||
|
||||
@@ -2047,14 +2070,14 @@ template<class T> using is_const_and_volatile =
|
||||
</div>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 43. Using mp_invoke to invoke a list of metafunctions, technique 2</div>
|
||||
<div class="title">Code Example 44. Using mp_invoke to invoke a list of metafunctions, technique 2</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>template<class T> using is_const_and_volatile =
|
||||
mp_all<mp_transform_q<mp_bind_back<mp_invoke, T>, LQ>>;</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 44. Using mp_invoke to invoke a list of metafunctions, technique 3</div>
|
||||
<div class="title">Code Example 45. Using mp_invoke to invoke a list of metafunctions, technique 3</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>template<class T> using is_const_and_volatile =
|
||||
mp_all<mp_transform<mp_invoke, LQ, mp_fill<LQ, T>>>;</code></pre>
|
||||
@@ -2075,7 +2098,7 @@ template<class T> using is_const_and_volatile =
|
||||
<p><code>mp_assign<L1<T1…​>, L2<T2…​>></code> is an alias for <code>L1<T2…​></code>. That is, it replaces the elements of <code>L1</code> with those of <code>L2</code>.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 45. Using mp_assign with mp_list and std::tuple</div>
|
||||
<div class="title">Code Example 46. Using mp_assign with mp_list and std::tuple</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using L1 = std::tuple<long>;
|
||||
using L2 = mp_list<int, float>;
|
||||
@@ -2084,7 +2107,7 @@ using R1 = mp_assign<L1, L2>; // std::tuple<int, float></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 46. Using mp_assign with mp_list and std::pair</div>
|
||||
<div class="title">Code Example 47. Using mp_assign with mp_list and std::pair</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using L1 = std::pair<long, char>;
|
||||
using L2 = mp_list<int, float>;
|
||||
@@ -2143,7 +2166,7 @@ using R1 = mp_assign<L1, L2>; // std::pair<int, float></code></pre>
|
||||
<p><code>mp_clear<L<T…​>></code> is an alias for <code>L<></code>, that is, it removes the elements of <code>L</code>.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 47. Using mp_clear with std::tuple</div>
|
||||
<div class="title">Code Example 48. Using mp_clear with std::tuple</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using L1 = std::tuple<int, float>;
|
||||
using R1 = mp_clear<L1>; // std::tuple<></code></pre>
|
||||
@@ -2161,7 +2184,7 @@ using R1 = mp_clear<L1>; // std::tuple<></code></pre>
|
||||
<p><code>mp_transform<F, L1<T1…​>, L2<T2…​>, …​, Ln<Tn…​>></code> applies <code>F</code> to each successive tuple of elements and returns <code>L1<F<T1, T2, …​, Tn>…​></code>.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 48. Using mp_transform to produce a list of pointers from a list of pointees</div>
|
||||
<div class="title">Code Example 49. Using mp_transform to produce a list of pointers from a list of pointees</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>template<class T> using add_pointer_t =
|
||||
typename std::add_pointer<T>::type; // std::add_pointer_t in C++14
|
||||
@@ -2171,7 +2194,7 @@ using R1 = mp_transform<add_pointer_t, L1>; // std::tuple<void*, int*,
|
||||
</div>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 49. Using mp_transform to compare the contents of two lists of types</div>
|
||||
<div class="title">Code Example 50. Using mp_transform to compare the contents of two lists of types</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using L1 = std::tuple<void, int, float>;
|
||||
using L2 = mp_list<void, int, float>;
|
||||
@@ -2180,7 +2203,7 @@ using R1 = mp_all<mp_transform<std::is_same, L1, L2>>; // mp_true</c
|
||||
</div>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 50. Using mp_transform to compare the contents of two lists of integral constants</div>
|
||||
<div class="title">Code Example 51. Using mp_transform to compare the contents of two lists of integral constants</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>template<class T1, class T2> using eq = mp_bool<T1::value == T2::value>;
|
||||
|
||||
@@ -2271,7 +2294,7 @@ using R1 = mp_all<mp_transform<eq, L1, L2>>; // mp_true</code></pre>
|
||||
<p>As <code>mp_transform</code>, but takes a quoted metafunction.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 51. Using mp_transform_q to count the occurences of <code>void</code> in a list</div>
|
||||
<div class="title">Code Example 52. Using mp_transform_q to count the occurences of <code>void</code> in a list</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using L1 = std::tuple<void, int, float, void, int>;
|
||||
|
||||
@@ -2332,7 +2355,7 @@ using R1 = mp_apply<mp_plus,
|
||||
<code>F<T1, T2, …​, Tn></code>, and returns the result, where <code>Ti</code> are the corresponding elements of <code>Li</code>.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 52. Using mp_transform_if to replace the occurences of 'void' in a list with the corresponding elements of a second list</div>
|
||||
<div class="title">Code Example 53. Using mp_transform_if to replace the occurences of 'void' in a list with the corresponding elements of a second list</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using L1 = std::tuple<void, int, float, void, int>;
|
||||
using L2 = std::tuple<char[1], char[2], char[3], char[4], char[5]>;
|
||||
@@ -2406,7 +2429,7 @@ using R1 = mp_transform_if<first_is_void, second, L1, L2>;
|
||||
<p>As <code>mp_transform_if</code>, but takes quoted metafunctions.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 53. Using mp_transform_if_q to replace the occurences of 'void' in a list with the corresponding elements of a second list</div>
|
||||
<div class="title">Code Example 54. Using mp_transform_if_q to replace the occurences of 'void' in a list with the corresponding elements of a second list</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using L1 = std::tuple<void, int, float, void, int>;
|
||||
using L2 = std::tuple<char[1], char[2], char[3], char[4], char[5]>;
|
||||
@@ -2476,14 +2499,14 @@ using R1 = mp_transform_if_q<mp_bind<std::is_same, _1, void>, _2, L1, L
|
||||
<p><code>mp_fill<L<T…​>, V></code> returns <code>L<V, V, …​, V></code>, with the result having the same size as the input.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 54. Using mp_fill with std::tuple</div>
|
||||
<div class="title">Code Example 55. Using mp_fill with std::tuple</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using L1 = std::tuple<void, int, float>;
|
||||
using R1 = mp_fill<L1, double>; // std::tuple<double, double, double></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 55. Using mp_fill with std::pair</div>
|
||||
<div class="title">Code Example 56. Using mp_fill with std::pair</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using L1 = std::pair<int, float>;
|
||||
using R1 = mp_fill<L1, void>; // std::pair<void, void></code></pre>
|
||||
@@ -3128,7 +3151,7 @@ for the elements of <code>L<U1…​></code> and <code>mp_false</c
|
||||
<p><code>mp_sort<L, P></code> sorts the list <code>L</code> according to the strict weak ordering <code>mp_to_bool<P<T, U>></code>.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 56. Using mp_sort to sort a list of std::ratio values</div>
|
||||
<div class="title">Code Example 57. Using mp_sort to sort a list of std::ratio values</div>
|
||||
<div class="content">
|
||||
<pre>#include <ratio>
|
||||
|
||||
@@ -3213,7 +3236,7 @@ is <code>mp_size<L></code>.</p>
|
||||
<p><code>mp_fold<L<T1, T2, …​, Tn>, V, F></code> is <code>F< F< F< F<V, T1>, T2>, …​>, Tn></code>, or <code>V</code>, if <code>L</code> is empty.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 57. Using mp_fold to add the contents of a list of std::ratio values</div>
|
||||
<div class="title">Code Example 58. Using mp_fold to add the contents of a list of std::ratio values</div>
|
||||
<div class="content">
|
||||
<pre>#include <ratio>
|
||||
|
||||
@@ -3295,7 +3318,7 @@ using R1 = mp_fold<L1, std::ratio<0,1>, std::ratio_add>; // std::rat
|
||||
<p>Returns <code>std::forward<F>(f)</code>.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 58. Using mp_for_each and a C++14 lambda to print a tuple</div>
|
||||
<div class="title">Code Example 59. Using mp_for_each and a C++14 lambda to print a tuple</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>template<class... T> void print( std::tuple<T...> const & tp )
|
||||
{
|
||||
@@ -3336,7 +3359,7 @@ Only <code>constexpr</code> on C++14 and higher.</p>
|
||||
<p>Returns <code>mp_with_index<N::value>(i, f)</code>.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 59. Using mp_with_index and a C++14 lambda to print the active element of a variant</div>
|
||||
<div class="title">Code Example 60. Using mp_with_index and a C++14 lambda to print the active element of a variant</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>template<class... T> void print( std::variant<T...> const& v )
|
||||
{
|
||||
@@ -3493,7 +3516,7 @@ returns <code>mp_false</code>. If the application causes a substitution failure,
|
||||
returns <code>mp_true</code>. <code>mp_and<></code> is <code>mp_true</code>.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 60. mp_and behavior</div>
|
||||
<div class="title">Code Example 61. mp_and behavior</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using R1 = mp_and<mp_true, mp_true>; // mp_true
|
||||
|
||||
@@ -3519,7 +3542,7 @@ is an error because <code>void</code> does not have a nested <code>value</code>.
|
||||
mask substitution failures as <code>mp_and</code> does.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 61. mp_all behavior</div>
|
||||
<div class="title">Code Example 62. mp_all behavior</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using R1 = mp_all<mp_true, mp_true>; // mp_true
|
||||
|
||||
@@ -3543,7 +3566,7 @@ using R4 = mp_all<void, mp_true>; // compile-time error</code></pre>
|
||||
returns <code>mp_true</code>. If all results are <code>mp_false</code>, returns <code>mp_false</code>. <code>mp_or<></code> is <code>mp_false</code>.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 62. mp_or behavior</div>
|
||||
<div class="title">Code Example 63. mp_or behavior</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using R1 = mp_or<mp_true, mp_false>; // mp_true
|
||||
|
||||
@@ -3567,7 +3590,7 @@ using R4 = mp_or<void, mp_true>; // compile-time error</code></pre>
|
||||
<code>mp_or</code>, but does not perform short-circuit evaluation.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 63. mp_any behavior</div>
|
||||
<div class="title">Code Example 64. mp_any behavior</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using R1 = mp_any<mp_true, mp_false>; // mp_true
|
||||
|
||||
|
@@ -169,6 +169,22 @@ When `mp_valid<F, T...>` is `mp_true`, `mp_defer<F, T...>` is a struct with a ne
|
||||
using LQ = mp_list<mp_quote<std::is_const>, mp_quote<std::is_volatile>>;
|
||||
```
|
||||
|
||||
## mp_quote_trait<F>
|
||||
|
||||
template<template<class...> class F> struct mp_quote_trait
|
||||
{
|
||||
template<class... T> using fn = typename F<T...>::type;
|
||||
};
|
||||
|
||||
`mp_quote_trait<F>` transforms the C++03-style trait `F` into a quoted metafunction.
|
||||
|
||||
.Using mp_quote_trait with std::add_pointer
|
||||
```
|
||||
using L1 = mp_list<int, void, float>;
|
||||
using R1 = mp_transform_q<mp_quote_trait<std::add_pointer>, L1>;
|
||||
// mp_list<int*, void*, float*>
|
||||
```
|
||||
|
||||
## mp_invoke<Q, T...>
|
||||
|
||||
template<class Q, class... T> using mp_invoke = typename Q::template fn<T...>;
|
||||
|
Reference in New Issue
Block a user