From 85c342944b3ded8e337bf5646374993b8d62dcea Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 17 Jun 2017 19:39:13 +0300 Subject: [PATCH] Add mp_fold example --- doc/html/mp11.html | 21 +++++++++++++++------ doc/mp11/algorithm.adoc | 8 ++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/doc/html/mp11.html b/doc/html/mp11.html index e5cab1b..37b9ade 100644 --- a/doc/html/mp11.html +++ b/doc/html/mp11.html @@ -3212,6 +3212,15 @@ 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.

+
+
Code Example 57. 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>

@@ -3286,7 +3295,7 @@ is mp_size<L>.

Returns std::forward<F>(f).

-
Code Example 57. Using mp_for_each and a C++14 lambda to print a tuple
+
Code Example 58. Using mp_for_each and a C++14 lambda to print a tuple
template<class... T> void print( std::tuple<T...> const & tp )
 {
@@ -3327,7 +3336,7 @@ Only constexpr on C++14 and higher.

Returns mp_with_index<N::value>(i, f).

-
Code Example 58. Using mp_with_index and a C++14 lambda to print the active element of a variant
+
Code Example 59. Using mp_with_index and a C++14 lambda to print the active element of a variant
template<class... T> void print( std::variant<T...> const& v )
 {
@@ -3484,7 +3493,7 @@ returns mp_false. If the application causes a substitution failure,
 returns mp_true. mp_and<> is mp_true.

-
Code Example 59. mp_and behavior
+
Code Example 60. mp_and behavior
using R1 = mp_and<mp_true, mp_true>;   // mp_true
 
@@ -3510,7 +3519,7 @@ is an error because void does not have a nested value.
 mask substitution failures as mp_and does.

-
Code Example 60. mp_all behavior
+
Code Example 61. mp_all behavior
using R1 = mp_all<mp_true, mp_true>;   // mp_true
 
@@ -3534,7 +3543,7 @@ using R4 = mp_all<void, mp_true>;      // compile-time error
returns mp_true. If all results are mp_false, returns mp_false. mp_or<> is mp_false.

-
Code Example 61. mp_or behavior
+
Code Example 62. mp_or behavior
using R1 = mp_or<mp_true, mp_false>;   // mp_true
 
@@ -3558,7 +3567,7 @@ using R4 = mp_or<void, mp_true>;       // compile-time error
mp_or, but does not perform short-circuit evaluation.

-
Code Example 62. mp_any behavior
+
Code Example 63. mp_any behavior
using R1 = mp_any<mp_true, mp_false>;  // mp_true
 
diff --git a/doc/mp11/algorithm.adoc b/doc/mp11/algorithm.adoc
index 855fdef..cd61207 100644
--- a/doc/mp11/algorithm.adoc
+++ b/doc/mp11/algorithm.adoc
@@ -509,6 +509,14 @@ is `mp_size`.
 
 `mp_fold, V, F>` is `F< F< F< F, T2>, ...>, Tn>`, or `V`, if `L` is empty.
 
+.Using mp_fold to add the contents of a list of std::ratio values
+----
+#include 
+
+using L1 = mp_list, std::ratio<1,4>, std::ratio<1,2>>;
+using R1 = mp_fold, std::ratio_add>; // std::ratio<7,8>
+----
+
 ## mp_reverse_fold
 
     template class F> using mp_reverse_fold =