#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>+
From 85c342944b3ded8e337bf5646374993b8d62dcea Mon Sep 17 00:00:00 2001
From: Peter Dimov 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.
#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_size<L>
.
Returns std::forward<F>(f)
.
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)
.
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
.
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.
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
.
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.
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 =