1
0
forked from boostorg/mp11
This commit is contained in:
zerotypos-found
2018-01-23 11:57:55 +09:00
parent 8bffdd64b5
commit 4fee76f416
5 changed files with 12 additions and 12 deletions

View File

@ -133,7 +133,7 @@ To do that, we need to first convert `std::tuple<int, float, void*>` to
`mp_list<int, float, void*>`, apply `add_pointer` to each element obtaining
`mp_list<int*, float*, void$$**$$>`, then convert that back to `std::tuple`.
These conversion steps are a quite common occurence, and we'll write a
These conversion steps are a quite common occurrence, and we'll write a
primitive that helps us perform them, called `mp_rename`. We want
```
mp_rename<std::tuple<int, float, void*>, mp_list>
@ -1097,7 +1097,7 @@ template<class T, class U> using sizeof_less = mp_bool<(sizeof(T) < sizeof(U))>;
Finally, let me show the implementations of `mp_count` and `mp_count_if`, for
no reason other than I find them interesting. `mp_count<L, V>` returns the
number of occurences of the type `V` in the list `L`; `mp_count_if<L, P>`
number of occurrences of the type `V` in the list `L`; `mp_count_if<L, P>`
counts the number of types in `L` for which `P<T>` is `true`.
As a first step, I'll implement `mp_plus`. `mp_plus` is a variadic (not just
@ -1175,7 +1175,7 @@ whether the list `L` contains the type `V`:
template<class L, class V> using mp_contains = mp_bool<mp_count<L, V>::value != 0>;
```
At first sight, this implementation appears horribly naive and inefficient --
why would we need to count all the occurences just to throw that away if we're
why would we need to count all the occurrences just to throw that away if we're
only interested in a boolean result -- but it's actually pretty competitive and
perfectly usable. We just need to add one slight optimization to `mp_plus`, the
engine behind `mp_count` and `mp_contains`:

View File

@ -681,7 +681,7 @@ as the first argument are:
|g$$++$$ 4.9.2, recursive |0.9 |4.7 |14.2 |32.4 |DNF |||
|===
To improve upon this apalling result, we'll again exploit pack expansion into a
To improve upon this appalling result, we'll again exploit pack expansion into a
function call, but in a novel way. Let's suppose that we need to access the
fourth element (`I = 3`). We'll generate the function signature
```
@ -838,7 +838,7 @@ one. We can pretty much tell who's going to win, and by how much.
The final algorithm that I'll bring to your attention is `mp_find_index`.
`mp_find_index<L, V>` returns an integral constant of type `size_t` with a
value that is the index of the first occurence of `V` in `L`. If `V` is not in
value that is the index of the first occurrence of `V` in `L`. If `V` is not in
`L`, the return value is the size of `L`.
We'll start with the recursive implementation, as usual:
@ -974,7 +974,7 @@ needs to manipulate type lists of length 300.
Note that once we have `mp_drop` and `mp_find_index`, we can derive the
`mp_find<L, V>` algorithm, which returns the suffix of `L` starting with the
first occurence of `V`, if any, and an empty list otherwise, by using
first occurrence of `V`, if any, and an empty list otherwise, by using
`mp_drop<L, mp_find_index<L, V>>`.
## Conclusion

View File

@ -71,7 +71,7 @@ using R1 = mp_all<mp_transform<eq, L1, L2>>; // mp_true
As `mp_transform`, but takes a quoted metafunction.
.Using mp_transform_q to count the occurences of `void` in a list
.Using mp_transform_q to count the occurrences of `void` in a list
```
using L1 = std::tuple<void, int, float, void, int>;
@ -97,7 +97,7 @@ using R1 = mp_apply<mp_plus,
`mp_transform_if<P, F, L1, L2, ..., Ln>` replaces the elements of the list `L1` for which `mp_to_bool<P<T1, T2, ..., Tn>>` is `mp_true` with
`F<T1, T2, ..., Tn>`, and returns the result, where `Ti` are the corresponding elements of `Li`.
.Using mp_transform_if to replace the occurences of 'void' in a list with the corresponding elements of a second list
.Using mp_transform_if to replace the occurrences of 'void' in a list with the corresponding elements of a second list
```
using L1 = std::tuple<void, int, float, void, int>;
using L2 = std::tuple<char[1], char[2], char[3], char[4], char[5]>;
@ -128,7 +128,7 @@ using R1 = mp_transform_if<first_is_void, second, L1, L2>;
As `mp_transform_if`, but takes quoted metafunctions.
.Using mp_transform_if_q to replace the occurences of 'void' in a list with the corresponding elements of a second list
.Using mp_transform_if_q to replace the occurrences of 'void' in a list with the corresponding elements of a second list
```
using L1 = std::tuple<void, int, float, void, int>;
using L2 = std::tuple<char[1], char[2], char[3], char[4], char[5]>;
@ -531,7 +531,7 @@ As `mp_max_element`, but takes a quoted metafunction.
template<class L, class V> using mp_find = /*...*/;
`mp_find<L, V>` returns the index at which the type `V` is located in the list `L`. It's an alias for `mp_size_t<I>`,
where `I` is the zero-based index of the first occurence of `V` in `L`. If `L` does not contain `V`, `mp_find<L, V>`
where `I` is the zero-based index of the first occurrence of `V` in `L`. If `L` does not contain `V`, `mp_find<L, V>`
is `mp_size<L>`.
## mp_find_if<L, P>

View File

@ -156,7 +156,7 @@ That is, when our `common_tuple` causes a substitution failure instead of a hard
and `common_type_t`, which is defined as `typename common_type<...>::type`, will also cause a substitution failure.
As another example, consider the hypothetical type `expected<T, E...>` that represents either a successful return with a value of `T`,
or an unsucessful return with an error code of some type in the list `E...`. The common type of `expected<T1, E1, E2, E3>` and
or an unsuccessful return with an error code of some type in the list `E...`. The common type of `expected<T1, E1, E2, E3>` and
`expected<T2, E1, E4, E5>` is `expected<common_type_t<T1, T2>, E1, E2, E3, E4, E5>`. That is, the possible return values are
combined into their common type, and we take the union of the set of error types.

View File

@ -55,7 +55,7 @@ replaces the existing element with `T`.
If the map `M` does not contain an element with a key `mp_first<T>`, inserts it (using `mp_push_back<M, T>`); otherwise,
replaces the existing element `L<X, Y...>` with `L<X, F<X, Y...>>`.
.Using mp_map_update to count the number of occurences of types in a list
.Using mp_map_update to count the number of occurrences of types in a list
```
template<class T, class U> using inc2nd = mp_int<U::value + 1>;