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

131 lines
3.9 KiB
Plaintext
Raw Normal View History

2017-06-07 00:02:25 +03:00
////
Copyright 2017 Peter Dimov
2017-03-16 19:45:47 +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
////
[#function]
# Helper Metafunctions, <boost/mp11/function.hpp>
:toc:
2017-06-07 00:13:13 +03:00
:toc-title:
2017-06-07 00:02:25 +03:00
:idprefix:
## mp_void<T...>
2017-03-16 19:45:47 +02:00
template<class... T> using mp_void = void;
Same as `std::void_t` from C++17.
2017-06-07 00:02:25 +03:00
## mp_and<T...>
2017-03-16 19:45:47 +02:00
template<class... T> using mp_and = /*...*/;
2017-05-24 05:58:06 +03:00
`mp_and<T...>` applies `mp_to_bool` to the types in `T...`, in order. If the result of an application is `mp_false`, `mp_and`
returns `mp_false`. If the application causes a substitution failure, returns `mp_false`. If all results are `mp_true`,
returns `mp_true`. `mp_and<>` is `mp_true`.
2017-06-10 03:44:31 +03:00
.mp_and behavior
```
using R1 = mp_and<mp_true, mp_true>; // mp_true
2017-06-09 20:35:21 +03:00
2017-06-10 03:44:31 +03:00
using R2 = mp_and<mp_false, void>; // mp_false, void is not reached
2017-06-09 20:35:21 +03:00
2017-06-10 03:44:31 +03:00
using R3 = mp_and<mp_false, mp_false>; // mp_false
2017-06-09 20:35:21 +03:00
2017-06-10 03:44:31 +03:00
using R4 = mp_and<void, mp_true>; // mp_false (!)
```
2017-03-16 19:45:47 +02:00
2017-06-07 00:02:25 +03:00
## mp_all<T...>
2017-03-16 19:45:47 +02:00
template<class... T> using mp_all = /*...*/;
`mp_all<T...>` is `mp_true` if `mp_to_bool<U>` is `mp_true` for all types `U` in `T...`, `mp_false` otherwise. Same as
`mp_and`, but does not perform short-circuit evaluation. `mp_and<mp_false, void>` is `mp_false`, but `mp_all<mp_false, void>`
2017-05-24 05:58:06 +03:00
is an error because `void` does not have a nested `value`. The upside is that `mp_all` is potentially faster and does not
mask substitution failures as `mp_and` does.
2017-06-10 03:44:31 +03:00
.mp_all behavior
```
using R1 = mp_all<mp_true, mp_true>; // mp_true
2017-06-09 20:35:21 +03:00
2017-06-10 03:44:31 +03:00
using R2 = mp_all<mp_false, void>; // compile-time error
2017-06-09 20:35:21 +03:00
2017-06-10 03:44:31 +03:00
using R3 = mp_all<mp_false, mp_false>; // mp_false
2017-06-09 20:35:21 +03:00
2017-06-10 03:44:31 +03:00
using R4 = mp_all<void, mp_true>; // compile-time error
```
2017-03-16 19:45:47 +02:00
2017-06-07 00:02:25 +03:00
## mp_or<T...>
2017-03-16 19:45:47 +02:00
template<class... T> using mp_or = /*...*/;
`mp_or<T...>` applies `mp_to_bool` to the types in `T...`, in order. If the result of an application is `mp_true`, `mp_or`
returns `mp_true`. If all results are `mp_false`, returns `mp_false`. `mp_or<>` is `mp_false`.
2017-06-10 03:44:31 +03:00
.mp_or behavior
```
using R1 = mp_or<mp_true, mp_false>; // mp_true
2017-06-09 20:35:21 +03:00
2017-06-10 03:44:31 +03:00
using R2 = mp_or<mp_true, void>; // mp_true, void is not reached
2017-06-09 20:35:21 +03:00
2017-06-10 03:44:31 +03:00
using R3 = mp_or<mp_false, mp_false>; // mp_false
2017-06-09 20:35:21 +03:00
2017-06-10 03:44:31 +03:00
using R4 = mp_or<void, mp_true>; // compile-time error
```
2017-03-16 19:45:47 +02:00
2017-06-07 00:02:25 +03:00
## mp_any<T...>
2017-03-16 19:45:47 +02:00
template<class... T> using mp_any = /*...*/;
`mp_any<T...>` is `mp_true` if `mp_to_bool<U>` is `mp_true` for any type `U` in `T...`, `mp_false` otherwise. Same as
`mp_or`, but does not perform short-circuit evaluation.
2017-06-10 03:44:31 +03:00
.mp_any behavior
```
using R1 = mp_any<mp_true, mp_false>; // mp_true
2017-06-09 20:35:21 +03:00
2017-06-10 03:44:31 +03:00
using R2 = mp_any<mp_true, void>; // compile-time error
2017-06-09 20:35:21 +03:00
2017-06-10 03:44:31 +03:00
using R3 = mp_any<mp_false, mp_false>; // mp_false
2017-06-09 20:35:21 +03:00
2017-06-10 03:44:31 +03:00
using R4 = mp_any<void, mp_true>; // compile-time error
```
2017-03-16 19:45:47 +02:00
2017-06-07 00:02:25 +03:00
## mp_same<T...>
2017-05-18 14:20:58 +03:00
template<class... T> using mp_same = /*...*/;
`mp_same<T...>` is `mp_true` if all the types in `T...` are the same type, `mp_false` otherwise. `mp_same<>` is `mp_true`.
2017-06-07 00:02:25 +03:00
## mp_plus<T...>
2017-05-24 01:52:11 +03:00
template<class... T> using mp_plus = /*...*/;
`mp_plus<T...>` is an integral constant type with a value that is the sum of `U::value` for all types `U` in `T...`.
`mp_plus<>` is `mp_int<0>`.
2017-10-15 15:52:32 +03:00
## mp_less<T1, T2>
template<class T1, class T2> using mp_less = /*...*/;
`mp_less<T1, T2>` is `mp_true` when the numeric value of `T1::value` is less than the numeric value of `T2::value`,
`mp_false` otherwise.
(Note that this is not necessarily the same as `T1::value < T2::value` when comparing between signed and unsigned types;
`-1 < 1u` is `false`, but `mp_less<mp_int\<-1>, mp_size_t<1>>` is `mp_true`.)
## mp_min<T1, T...>
template<class T1, class... T> using mp_min = mp_min_element<mp_list<T1, T...>, mp_less>;
`mp_min<T...>` returns the type `U` in `T...` with the lowest `U::value`.
## mp_max<T1, T...>
template<class T1, class... T> using mp_max = mp_max_element<mp_list<T1, T...>, mp_less>;
`mp_max<T...>` returns the type `U` in `T...` with the highest `U::value`.