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

101 lines
2.9 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
////
[#utility]
# Utility Components, <boost/mp11/utility.hpp>
:toc:
2017-06-07 00:13:13 +03:00
:toc-title:
2017-06-07 00:02:25 +03:00
:idprefix:
## mp_identity<T>
2017-03-14 22:57:07 +02:00
template<class T> struct mp_identity
{
using type = T;
};
2017-06-07 00:02:25 +03:00
## mp_identity_t<T>
2017-03-14 22:57:07 +02:00
template<class T> using mp_identity_t = T;
2017-06-07 00:02:25 +03:00
## mp_inherit<T...>
2017-03-14 22:57:07 +02:00
template<class... T> struct mp_inherit: T... {};
2017-06-07 00:02:25 +03:00
## mp_if_c<C, T, E...>
2017-05-18 14:59:46 +03:00
template<bool C, class T, class... E> using mp_if_c = /*...*/;
2017-03-14 22:57:07 +02:00
2017-05-18 14:59:46 +03:00
`mp_if_c<true, T, E...>` is an alias for `T`. `mp_if_c<false, T, E>` is an alias for `E`. Otherwise, the result is a substitution failure.
2017-06-09 20:35:21 +03:00
Examples:
2017-05-18 14:59:46 +03:00
using R1 = mp_if_c<true, int, void>; // int
2017-06-09 20:35:21 +03:00
2017-05-18 14:59:46 +03:00
using R2 = mp_if_c<flase, int, void>; // void
2017-06-09 20:35:21 +03:00
template<class I> using void_if_5 = mp_if_c<I::value == 5, void>;
// `void` when `I::value` is 5, substitution failure otherwise
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_if<C, T, E...>
2017-06-09 20:35:21 +03:00
template<class C, class T, class E...> using mp_if =
mp_if_c<static_cast<bool>(C::value), T, E...>;
2017-03-14 22:57:07 +02:00
2017-05-18 14:59:46 +03:00
Like `mp_if_c`, but the first argument is a type.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_eval_if_c<C, T, F, U...>
2017-03-14 22:57:07 +02:00
template<bool C, class T, template<class...> class F, class... U> using mp_eval_if_c = /*...*/;
2017-05-19 03:22:53 +03:00
`mp_eval_if_c<C, T, F, U...>` is an alias for `T` when `C` is `true`, for `F<U...>` otherwise. Its purpose
2017-03-14 22:57:07 +02:00
is to avoid evaluating `F<U...>` when the condition is `true` as it may not be valid in this case.
2017-06-07 00:02:25 +03:00
## mp_eval_if<C, T, F, U...>
2017-06-09 20:35:21 +03:00
template<class C, class T, template<class...> class F, class... U> using mp_eval_if =
mp_eval_if_c<static_cast<bool>(C::value), T, F, U...>;
2017-03-14 22:57:07 +02:00
Like `mp_eval_if_c`, but the first argument is a type.
2017-06-07 00:02:25 +03:00
## mp_eval_if_q<C, T, Q, U...>
2017-06-09 20:35:21 +03:00
template<class C, class T, class Q, class... U> using mp_eval_if_q =
mp_eval_if<C, T, Q::template fn, U...>;
2017-05-19 03:22:53 +03:00
Like `mp_eval_if`, but takes a quoted metafunction.
2017-06-07 00:02:25 +03:00
## mp_valid<F, T...>
2017-03-14 22:57:07 +02:00
template<template<class...> class F, class... T> using mp_valid = /*...*/;
`mp_valid<F, T...>` is an alias for `mp_true` when `F<T...>` is a valid expression, for `mp_false` otherwise.
2017-06-07 00:02:25 +03:00
## mp_defer<F, T...>
2017-03-14 22:57:07 +02:00
template<template<class...> class F, class... T> using mp_defer = /*...*/;
When `mp_valid<F, T...>` is `mp_true`, `mp_defer<F, T...>` is a struct with a nested type `type` which is an alias for `F<T...>`. Otherwise,
`mp_defer<F, T...>` is an empty struct.
2017-06-07 00:02:25 +03:00
## mp_quote<F>
template<template<class...> class F> struct mp_quote
2017-03-14 22:57:07 +02:00
{
template<class... T> using fn = F<T...>;
2017-03-14 22:57:07 +02:00
};
`mp_quote<F>` transforms the template `F` into a type with a nested template `fn` such that `fn<T...>` returns `F<T...>`.
2017-03-14 22:57:07 +02:00
2017-06-07 00:02:25 +03:00
## mp_invoke<Q, T...>
2017-03-20 16:23:52 +02:00
template<class Q, class... T> using mp_invoke = typename Q::template fn<T...>;
2017-03-14 22:57:07 +02:00
`mp_invoke<Q, T...>` evaluates the nested template `fn` of a quoted metafunction. `mp_invoke<mp_quote<F>, T...>` returns `F<T...>`.