From 7debd787dddd9d88cf0fd01be06f2998d0ddaed0 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 23 Mar 2020 02:59:00 +0200 Subject: [PATCH] Document mp_iterate --- doc/mp11/algorithm.adoc | 54 +++++++++++++++++++++++++++++++++++++++++ doc/mp11/changelog.adoc | 1 + 2 files changed, 55 insertions(+) diff --git a/doc/mp11/algorithm.adoc b/doc/mp11/algorithm.adoc index fae2cf0..ab31f52 100644 --- a/doc/mp11/algorithm.adoc +++ b/doc/mp11/algorithm.adoc @@ -739,6 +739,60 @@ using R1 = mp_partial_sum, mp_plus>; // mp_list_c + + template class F, template class R> + using mp_iterate = /*...*/; + +`mp_iterate` applies `R` to `V` successively until that's no longer possible, +yielding the sequence `V`, `R`, `R>`, `R>>`... + +It then returns an `mp_list` whose elements are formed by applying `F` to the above +sequence of values. That is, it returns `mp_list, F>, F>>, ...>`. + +`mp_iterate` is in a way the reverse operation of `mp_reverse_fold`. Given + + template struct cons {}; + struct nil {}; + +`mp_reverse_fold, nil, cons>` produces `cons>>`, +which when passed as `V` to `mp_iterate` recovers the original +`mp_list`. + +.Using mp_iterate +---- +struct X1 {}; +struct X2 {}; +struct X3 {}; + +using L1 = mp_list; +using R1 = mp_iterate; // L1 + +template struct cons {}; +struct nil {}; + +using V2 = mp_reverse_fold; // cons>> +using R2 = mp_iterate; // L1 + +struct Y1 {}; +struct Y2 { using value_type = double; using next_type = Y1; }; +struct Y3 { using value_type = float; using next_type = Y2; }; +struct Y4 { using value_type = int; using next_type = Y3; }; + +template using value_type = typename T::value_type; +template using next_type = typename T::next_type; + +using R3 = mp_iterate; // mp_list +using R4 = mp_iterate; // mp_list +---- + +## mp_iterate_q + + template using mp_iterate_q = + mp_iterate; + +As `mp_iterate`, but takes quoted metafunctions. + ## mp_unique template using mp_unique = /*...*/; diff --git a/doc/mp11/changelog.adoc b/doc/mp11/changelog.adoc index 098c59e..c410844 100644 --- a/doc/mp11/changelog.adoc +++ b/doc/mp11/changelog.adoc @@ -18,6 +18,7 @@ http://www.boost.org/LICENSE_1_0.txt * Added `mp_compose` * Added `mp_power_set` * Added `mp_partial_sum` +* Added `mp_iterate` ## Changes in 1.70.0