diff --git a/doc/mp11/definitions.adoc b/doc/mp11/definitions.adoc index 3e3eee0..87f0814 100644 --- a/doc/mp11/definitions.adoc +++ b/doc/mp11/definitions.adoc @@ -51,3 +51,10 @@ using M1 = std::tuple, std::pair, using M2 = mp_list, mp_list, mp_list>; ``` + +A _value list_ is a template class whose parameters are all values (non-type template parameters.) Value lists +match `template class L`, and require {cpp}17 (because `auto` template parameters are a {cpp}17 feature.) + +Value lists are only supported by a handful of the primitives. Mp11's primary focus is on type manipulation. For +working with lists of values, the usual approach is to convert the value list to a type list using `mp_rename`, +manipulate the type list, then convert back to a value list using `mp_rename_v`. diff --git a/doc/mp11/integral.adoc b/doc/mp11/integral.adoc index 0a10cec..af89151 100644 --- a/doc/mp11/integral.adoc +++ b/doc/mp11/integral.adoc @@ -48,3 +48,13 @@ Same as `std::false_type`. ## mp_size_t template using mp_size_t = std::integral_constant; + +## mp_value + + template using mp_value = std::integral_constant; + +When a value list is converted to a type list, either explicitly via `mp_rename`, or +implicitly by a primitive that supports value lists directly, its values are converted +to types by wrapping then with `mp_value`. + +Requires {cpp}17. diff --git a/doc/mp11/list.adoc b/doc/mp11/list.adoc index 4559f91..7e0abe4 100644 --- a/doc/mp11/list.adoc +++ b/doc/mp11/list.adoc @@ -33,6 +33,12 @@ the list. using L1 = mp_list_c; // mp_list, mp_int<3>> ``` +## mp_list_v + + template struct mp_list_v {}; + +The standard value list type of Mp11. Requires {cpp}17. + ## mp_is_list template using mp_is_list = /*...*/; @@ -46,6 +52,8 @@ using L1 = mp_list_c; // mp_list, mp_int<3>> `mp_size` returns the number of elements in the list `L`, as a `mp_size_t`. In other words, `mp_size>` is an alias for `mp_size_t`. +Supports value lists as `L` under {cpp}17. + .Using mp_size with mp_list ``` using L1 = mp_list<>; @@ -64,12 +72,20 @@ using L3 = std::tuple; using R3 = mp_size; // mp_size_t\<1> ``` +.Using mp_size with mp_list_v +``` +using L4 = mp_list_v<1, false, 8ull>; +using R4 = mp_size; // mp_size_t\<3> +``` + ## mp_empty template using mp_empty = mp_bool::value == 0>; `mp_empty` is an alias for `mp_true` if the list `L` is empty, for `mp_false` otherwise. +Supports value lists as `L` under {cpp}17. + .Using mp_empty with std::tuple ``` using L1 = std::tuple; @@ -253,6 +269,8 @@ using R2 = mp_push_back; // mp_list` changes the type of the list `L` to `Y`. That is, `mp_rename, Y>` is an alias for `Y`. +Supports value lists as `L` under {cpp}17. In that case, `mp_rename, Y>` is `Y...>`. + .Using mp_rename to rename std::pair to std::tuple ``` using L1 = std::pair; @@ -265,6 +283,12 @@ using L2 = std::tuple; using R2 = mp_rename; // mp_list ``` +.Using mp_rename to convert a value list to a type list +``` +using L3 = mp_list_v; +using R3 = mp_rename; // mp_list> +``` + ## mp_apply template class F, class L> using mp_apply = mp_rename; @@ -293,6 +317,22 @@ using R1 = mp_apply_q, L2>; // R1 is std::tuple ``` +## mp_rename_v + + template class Y> using mp_rename_v = /*...*/; + +Requires {cpp}17. + +For a value list `L`, `mp_rename_v, Y>` is `Y`. + +For a type list `L`, `mp_rename_v, Y>` is an alias for `Y`. + +.Using mp_rename_v to convert a type list to a value list +``` +using L1 = mp_list>; +using R1 = mp_rename_v; // mp_list_v; +``` + ## mp_append template using mp_append = /*...*/; @@ -361,7 +401,7 @@ using L2 = std::tuple; using R2 = mp_replace_second; // std::tuple ``` -.Using mp_replace_front with mp_list +.Using mp_replace_second with mp_list ``` using L3 = mp_list; using R3 = mp_replace_second; // mp_list;