1
0
forked from boostorg/mp11
Files
boost_mp11/doc/mp11/algorithm.adoc

306 lines
10 KiB
Plaintext
Raw Normal View History

2017-06-07 00:02:25 +03:00
////
Copyright 2017 Peter Dimov
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
Distributed under the Boost Software License, Version 1.0.
See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt
////
[#algorithm]
# Algorithms, <boost/mp11/algorithm.hpp>
:toc:
2017-06-07 00:13:13 +03:00
:toc-title:
2017-06-07 00:02:25 +03:00
:idprefix:
## mp_assign<L1, L2>
2017-03-14 22:57:07 +02:00
template<class L1, class L2> using mp_assign = /*...*/;
2017-03-15 19:43:06 +02:00
`mp_assign<L1<T1...>, L2<T2...>>` is an alias for `L1<T2...>`. That is, it replaces the elements of `L1` with those of `L2`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_clear<L>
2017-03-14 22:57:07 +02:00
template<class L> using mp_clear = mp_assign<L, mp_list<>>;
2017-03-15 19:43:06 +02:00
`mp_clear<L<T...>>` is an alias for `L<>`, that is, it removes the elements of `L`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_transform<F, L...>
2017-03-14 22:57:07 +02:00
template<template<class...> class F, class... L> using mp_transform = /*...*/;
2017-03-15 19:43:06 +02:00
`mp_transform<F, L1<T1...>, L2<T2...>, ..., Ln<Tn...>>` applies `F` to each successive tuple of elements and returns `L1<F<T1, T2, ..., Tn>...>`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_transform_q<Q, L...>
2017-05-10 00:39:18 +03:00
template<class Q, class... L> using mp_transform_q = mp_transform<Q::template fn, L...>;
As `mp_transform`, but takes a quoted metafunction.
2017-06-07 00:02:25 +03:00
## mp_transform_if<P, F, L...>
2017-03-18 20:36:58 +02:00
template<template<class...> class P, template<class...> class F, class L...> using mp_transform_if = /*...*/;
2017-03-15 19:43:06 +02:00
2017-03-25 03:02:59 +02:00
`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
2017-03-18 20:36:58 +02:00
`F<T1, T2, ..., Tn>`, and returns the result, where `Ti` are the corresponding elements of `Li`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_transform_if_q<Qp, Qf, L...>
2017-05-25 21:31:03 +03:00
template<class Qp, class Qf, class... L> using mp_transform_if_q = mp_transform_if<Qp::template fn, Qf::template fn, L...>;
As `mp_transform_if`, but takes a quoted metafunction.
2017-06-07 00:02:25 +03:00
## mp_fill<L, V>
2017-03-14 22:57:07 +02:00
template<class L, class V> using mp_fill = /*...*/;
2017-03-15 19:43:06 +02:00
`mp_fill<L<T...>, V>` returns `L<V, V, ..., V>`, with the result having the same size as the input.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_count<L, V>
2017-03-14 22:57:07 +02:00
template<class L, class V> using mp_count = /*...*/;
2017-03-15 19:43:06 +02:00
`mp_count<L, V>` returns `mp_size_t<N>`, where `N` is the number of elements of `L` same as `V`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_count_if<L, P>
2017-03-14 22:57:07 +02:00
template<class L, template<class...> class P> using mp_count_if = /*...*/;
2017-03-15 19:43:06 +02:00
2017-05-25 21:31:45 +03:00
`mp_count_if<L, P>` returns `mp_size_t<N>`, where `N` is the number of elements `T` of `L` for which `mp_to_bool<P<T>>` is `mp_true`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_contains<L, V>
2017-03-14 22:57:07 +02:00
template<class L, class V> using mp_contains = mp_to_bool<mp_count<L, V>>;
2017-03-15 19:43:06 +02:00
`mp_contains<L, V>` is `mp_true` when `L` contains an element `V`, `mp_false` otherwise.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_repeat_c<L, N>
2017-03-14 22:57:07 +02:00
template<class L, std::size_t N> using mp_repeat_c = /*...*/;
2017-03-15 19:43:06 +02:00
`mp_repeat_c<L, N>` returns a list of the same type as `L` that consists of `N` concatenated copies of `L`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_repeat<L, N>
2017-03-14 22:57:07 +02:00
template<class L, class N> using mp_repeat = /*...*/;
2017-03-15 19:43:06 +02:00
Same as `mp_repeat_c` but with a type argument `N`. The number of copies is `N::value` and must be nonnegative.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_product<F, L...>
2017-03-14 22:57:07 +02:00
template<template<class...> class F, class... L> using mp_product = /*...*/;
2017-03-15 19:43:06 +02:00
`mp_product<F, L1<T1...>, L2<T2...>, ..., Ln<Tn...>>` evaluates `F<U1, U2, ..., Un>` for values `Ui` taken from
the Cartesian product of the lists, as if the elements `Ui` are formed by `n` nested loops, each traversing `Li`.
It returns a list of type `L1` containing the results of the application of `F`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_product_q<Q, L...>
2017-05-13 21:07:54 +03:00
template<class Q, class... L> using mp_product_q = mp_product<Q::template fn, L...>;
As `mp_product`, but takes a quoted metafunction.
2017-06-07 00:02:25 +03:00
## mp_drop_c<L, N>
2017-03-14 22:57:07 +02:00
template<class L, std::size_t N> using mp_drop_c = /*...*/;
2017-03-15 19:43:06 +02:00
`mp_drop_c<L, N>` removes the first `N` elements of `L` and returns the result.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_drop<L, N>
2017-03-14 22:57:07 +02:00
template<class L, class N> using mp_drop = /*...*/;
2017-03-15 19:43:06 +02:00
Same as `mp_drop_c`, but with a type argument `N`. `N::value` must be a nonnegative number.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_iota_c<N>
2017-03-14 22:57:07 +02:00
template<std::size_t N> using mp_iota_c = /*...*/;
2017-03-15 19:43:06 +02:00
`mp_iota_c<N>` is an alias for `mp_list<mp_size_t<0>, mp_size_t<1>, ..., mp_size_t<N-1>>`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_iota<N>
2017-03-14 22:57:07 +02:00
template<class N> using mp_iota = /*...*/;
2017-03-15 19:43:06 +02:00
Same as `mp_iota_c`, but with a type argument `N`. `N::value` must be a nonnegative number. Returns
`mp_list<std::integral_constant<T, 0>, std::integral_constant<T, 1>, ..., std::integral_constant<T, N::value-1>>`
where `T` is the type of `N::value`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_at_c<L, I>
2017-03-14 22:57:07 +02:00
template<class L, std::size_t I> using mp_at_c = /*...*/;
2017-03-15 19:43:06 +02:00
`mp_at_c<L, I>` returns the `I`th element of `L`, zero-based.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_at<L, I>
2017-03-14 22:57:07 +02:00
template<class L, class I> using mp_at = /*...*/;
2017-03-15 19:43:06 +02:00
Same as `mp_at_c`, but with a type argument `I`. `I::value` must be a nonnegative number.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_take_c<L, N>
2017-03-14 22:57:07 +02:00
template<class L, std::size_t N> using mp_take_c = /*...*/;
2017-03-15 19:43:06 +02:00
`mp_take_c<L, N>` returns a list of the same type as `L` containing the first `N` elements of `L`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_take<L, N>
2017-03-14 22:57:07 +02:00
template<class L, class N> using mp_take = /*...*/;
2017-03-15 19:43:06 +02:00
Same as `mp_take_c`, but with a type argument `N`. `N::value` must be a nonnegative number.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_insert_c<L, I, T...>
2017-05-13 21:52:56 +03:00
template<class L, std::size_t I, class... T> using mp_insert_c = mp_append<mp_take_c<L, I>, mp_push_front<mp_drop_c<L, I>, T...>>;
Inserts the elements `T...` into the list `L` at position `I` (a zero-based index).
2017-06-07 00:02:25 +03:00
## mp_insert<L, I, T...>
2017-05-13 21:52:56 +03:00
template<class L, class I, class... T> using mp_insert = mp_append<mp_take<L, I>, mp_push_front<mp_drop<L, I>, T...>>;
Same as `mp_insert_c`, but with a type argument `I`.
2017-06-07 00:02:25 +03:00
## mp_erase_c<L, I, J>
2017-05-13 21:52:56 +03:00
template<class L, std::size_t I, std::size_t J> using mp_erase = mp_append<mp_take_c<L, I>, mp_drop_c<L, J>>;
Removes from the list `L` the elements with indices from `I` (inclusive) to `J` (exclusive).
2017-06-07 00:02:25 +03:00
## mp_erase<L, I, J>
2017-05-13 21:52:56 +03:00
template<class L, class I, class J> using mp_erase = mp_append<mp_take<L, I>, mp_drop<L, J>>;
Same as `mp_erase_c`, but with a type arguments `I` and `J`.
2017-06-07 00:02:25 +03:00
## mp_replace<L, V, W>
2017-03-14 22:57:07 +02:00
template<class L, class V, class W> using mp_replace = /*...*/;
2017-03-15 19:43:06 +02:00
Replaces all `V` elements of `L` with `W` and returns the result.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_replace_if<L, P, W>
2017-03-14 22:57:07 +02:00
template<class L, template<class...> class P, class W> using mp_replace_if = /*...*/;
2017-03-15 19:43:06 +02:00
Replaces all `T` elements of `L` for which `mp_to_bool<P<T>>` is `mp_true` with `W` and returns the result.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_replace_at_c<L, I, W>
2017-03-18 20:36:58 +02:00
template<class L, std::size_t I, class W> using mp_replace_at_c = /*...*/;
Replaces the element of `L` at zero-based index `I` with `W` and returns the result.
2017-06-07 00:02:25 +03:00
## mp_replace_at<L, I, W>
2017-03-18 20:36:58 +02:00
template<class L, class I, class W> using mp_replace_at = /*...*/;
Same as `mp_replace_at_c`, but with a type argument `I`. `I::value` must be a nonnegative number.
2017-06-07 00:02:25 +03:00
## mp_copy_if<L, P>
2017-03-14 22:57:07 +02:00
template<class L, template<class...> class P> using mp_copy_if = /*...*/;
2017-03-15 19:43:06 +02:00
Copies the elements `T` of `L` for which `mp_to_bool<P<T>>` is `mp_true` to a new list of the same type and returns it.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_remove<L, V>
2017-03-14 22:57:07 +02:00
template<class L, class V> using mp_remove = /*...*/;
2017-03-15 19:43:06 +02:00
Removes all `V` elements of `L` and returns the result.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_remove_if<L, P>
2017-03-14 22:57:07 +02:00
template<class L, template<class...> class P> using mp_remove_if = /*...*/;
2017-03-15 19:43:06 +02:00
Removes all elements `T` of `L` for which `mp_to_bool<P<T>>` is `mp_true` and returns the result.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_partition<L, P>
2017-03-14 22:57:07 +02:00
template<class L, template<class...> class P> using mp_partition = /*...*/;
2017-03-15 19:43:06 +02:00
`mp_partition<L<T...>, P>` partitions `L` into two lists `L<U1...>` and `L<U2...>` such that `mp_to_bool<P<T>>` is `mp_true`
for the elements of `L<U1...>` and `mp_false` for the elements of `L<U2...>`. Returns `L<L<U1...>, L<U2...>>`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_sort<L, P>
2017-03-14 22:57:07 +02:00
template<class L, template<class...> class P> using mp_sort = /*...*/;
2017-03-15 19:43:06 +02:00
`mp_sort<L, P>` sorts the list `L` according to the strict weak ordering `mp_to_bool<P<T, U>>`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_find<L, V>
2017-03-15 20:19:36 +02:00
template<class L, class V> using mp_find = /*...*/;
2017-05-13 20:56:52 +03:00
`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>`
is `mp_size<L>`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_find_if<L, P>
2017-03-15 20:19:36 +02:00
template<class L, template<class...> class P> using mp_find_if = /*...*/;
`mp_find_f<L, P>` is an alias for `mp_size_t<I>`, where `I` is the zero-based index of the first element `T` in `L` for which
2017-03-25 03:02:59 +02:00
`mp_to_bool<P<T>>` is `mp_true`. If there is no such element, `mp_find_if<L, P>` is `mp_size<L>`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_reverse<L>
2017-03-14 22:57:07 +02:00
template<class L> using mp_reverse = /*...*/;
2017-03-15 20:19:36 +02:00
`mp_reverse<L<T1, T2, ..., Tn>>` is `L<Tn, ..., T2, T1>`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_fold<L, V, F>
2017-03-14 22:57:07 +02:00
template<class L, class V, template<class...> class F> using mp_fold = /*...*/;
2017-03-15 20:19:36 +02:00
`mp_fold<L<T1, T2, ..., Tn>, V, F>` is `F< F< F< F<V, T1>, T2>, ...>, Tn>`, or `V`, if `L` is empty.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_reverse_fold<L, V, F>
2017-03-14 22:57:07 +02:00
template<class L, class V, template<class...> class F> using mp_reverse_fold = /*...*/;
2017-03-15 20:19:36 +02:00
`mp_reverse_fold<L<T1, T2, ..., Tn>, V, F>` is `F<T1, F<T2, F<..., F<Tn, V>>>>`, or `V`, if `L` is empty.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_unique<L>
2017-03-14 22:57:07 +02:00
template<class L> using mp_unique = /*...*/;
2017-03-15 20:19:36 +02:00
`mp_unique<L>` returns a list of the same type as `L` with the duplicate elements removed.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_all_of<L, P>
2017-03-14 22:57:07 +02:00
template<class L, template<class...> class P> using mp_all_of = mp_bool< mp_count_if<L, P>::value == mp_size<L>::value >;
2017-03-15 20:19:36 +02:00
`mp_all_of<L, P>` is `mp_true` when `P` holds for all elements of `L`, `mp_false` otherwise. When `L` is empty, the result is `mp_true`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_none_of<L, P>
2017-03-14 22:57:07 +02:00
template<class L, template<class...> class P> using mp_none_of = mp_bool< mp_count_if<L, P>::value == 0 >;
2017-03-15 20:19:36 +02:00
`mp_none_of<L, P>` is `mp_true` when `P` holds for no element of `L`, `mp_false` otherwise. When `L` is empty, the result is `mp_true`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_any_of<L, P>
2017-03-14 22:57:07 +02:00
template<class L, template<class...> class P> using mp_any_of = mp_bool< mp_count_if<L, P>::value != 0 >;
2017-03-15 20:19:36 +02:00
`mp_any_of<L, P>` is `mp_true` when `P` holds for at least one element of `L`, `mp_false` otherwise. When `L` is empty, the result is `mp_false`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_for_each<L>(f)
2017-05-13 00:23:58 +03:00
template<class L, class F> constexpr F mp_for_each(F&& f);
`mp_for_each<L>(f)` calls `f` with `T()` for each element `T` of the list `L`, in order.
2017-05-13 00:23:58 +03:00
Returns `std::forward<F>(f)`.
2017-06-07 00:02:25 +03:00
## mp_with_index<N>(i, f)
template<std::size_t N, class F> decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) mp_with_index( std::size_t i, F && f );
2017-05-31 19:56:18 +03:00
`mp_with_index<N>(i, f)` calls `f` with `mp_size_t<i>()` and returns the result. `i` must be less than `N`.
2017-05-31 19:56:18 +03:00
template<class N, class F> decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) mp_with_index( std::size_t i, F && f );
2017-05-31 19:56:18 +03:00
Returns `mp_with_index<N::value>(i, f)`.