forked from boostorg/mp11
Add mp_fold example
This commit is contained in:
@@ -3212,6 +3212,15 @@ is <code>mp_size<L></code>.</p>
|
||||
<div class="paragraph">
|
||||
<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="content">
|
||||
<pre>#include <ratio>
|
||||
|
||||
using L1 = mp_list<std::ratio<1,8>, std::ratio<1,4>, std::ratio<1,2>>;
|
||||
using R1 = mp_fold<L1, std::ratio<0,1>, std::ratio_add>; // std::ratio<7,8></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="mp_reverse_fold_l_v_f">mp_reverse_fold<L, V, F></h4>
|
||||
@@ -3286,7 +3295,7 @@ is <code>mp_size<L></code>.</p>
|
||||
<p>Returns <code>std::forward<F>(f)</code>.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">Code Example 57. Using mp_for_each and a C++14 lambda to print a tuple</div>
|
||||
<div class="title">Code Example 58. 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 )
|
||||
{
|
||||
@@ -3327,7 +3336,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 58. Using mp_with_index and a C++14 lambda to print the active element of a variant</div>
|
||||
<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="content">
|
||||
<pre class="highlight"><code>template<class... T> void print( std::variant<T...> const& v )
|
||||
{
|
||||
@@ -3484,7 +3493,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 59. mp_and behavior</div>
|
||||
<div class="title">Code Example 60. mp_and behavior</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using R1 = mp_and<mp_true, mp_true>; // mp_true
|
||||
|
||||
@@ -3510,7 +3519,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 60. mp_all behavior</div>
|
||||
<div class="title">Code Example 61. mp_all behavior</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using R1 = mp_all<mp_true, mp_true>; // mp_true
|
||||
|
||||
@@ -3534,7 +3543,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 61. mp_or behavior</div>
|
||||
<div class="title">Code Example 62. mp_or behavior</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using R1 = mp_or<mp_true, mp_false>; // mp_true
|
||||
|
||||
@@ -3558,7 +3567,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 62. mp_any behavior</div>
|
||||
<div class="title">Code Example 63. mp_any behavior</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code>using R1 = mp_any<mp_true, mp_false>; // mp_true
|
||||
|
||||
|
@@ -509,6 +509,14 @@ is `mp_size<L>`.
|
||||
|
||||
`mp_fold<L<T1, T2, ..., Tn>, V, F>` is `F< F< F< F<V, T1>, T2>, ...>, Tn>`, or `V`, if `L` is empty.
|
||||
|
||||
.Using mp_fold to add the contents of a list of std::ratio values
|
||||
----
|
||||
#include <ratio>
|
||||
|
||||
using L1 = mp_list<std::ratio<1,8>, std::ratio<1,4>, std::ratio<1,2>>;
|
||||
using R1 = mp_fold<L1, std::ratio<0,1>, std::ratio_add>; // std::ratio<7,8>
|
||||
----
|
||||
|
||||
## mp_reverse_fold<L, V, F>
|
||||
|
||||
template<class L, class V, template<class...> class F> using mp_reverse_fold =
|
||||
|
Reference in New Issue
Block a user