2017-03-14 22:57:07 +02:00
|
|
|
[/
|
|
|
|
|
/ Copyright 2017 Peter Dimov
|
|
|
|
|
/
|
|
|
|
|
/ 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)
|
|
|
|
|
/]
|
|
|
|
|
|
|
|
|
|
[section:utility Utility Components, `<boost/mp11/utility.hpp>`]
|
|
|
|
|
|
|
|
|
|
[section `mp_identity<T>`]
|
|
|
|
|
template<class T> struct mp_identity
|
|
|
|
|
{
|
|
|
|
|
using type = T;
|
|
|
|
|
};
|
|
|
|
|
[endsect]
|
|
|
|
|
|
|
|
|
|
[section `mp_identity_t<T>`]
|
|
|
|
|
template<class T> using mp_identity_t = T;
|
|
|
|
|
[endsect]
|
|
|
|
|
|
|
|
|
|
[section `mp_inherit<T...>`]
|
|
|
|
|
template<class... T> struct mp_inherit: T... {};
|
|
|
|
|
[endsect]
|
|
|
|
|
|
2017-05-18 14:59:46 +03:00
|
|
|
[section `mp_if_c<B, T, E...>`]
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
using R1 = mp_if_c<true, int, void>; // int
|
|
|
|
|
using R2 = mp_if_c<flase, int, void>; // void
|
|
|
|
|
|
|
|
|
|
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
|
|
|
[endsect]
|
|
|
|
|
|
|
|
|
|
[section `mp_if<C, T, E>`]
|
|
|
|
|
template<class C, class T, class E> using mp_if = mp_if_c<static_cast<bool>(C::value), T, E>;
|
|
|
|
|
|
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
|
|
|
[endsect]
|
|
|
|
|
|
|
|
|
|
[section `mp_eval_if_c<B, T, F, U...>`]
|
|
|
|
|
template<bool C, class T, template<class...> class F, class... U> using mp_eval_if_c = /*...*/;
|
|
|
|
|
|
|
|
|
|
`mp_eval_if_c<B, T, F, U...>` is an alias for `T` when `B` is `true`, for `F<U...>` otherwise. Its purpose
|
|
|
|
|
is to avoid evaluating `F<U...>` when the condition is `true` as it may not be valid in this case.
|
|
|
|
|
[endsect]
|
|
|
|
|
|
|
|
|
|
[section `mp_eval_if<C, T, F, U...>`]
|
|
|
|
|
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...>;
|
|
|
|
|
|
|
|
|
|
Like `mp_eval_if_c`, but the first argument is a type.
|
|
|
|
|
[endsect]
|
|
|
|
|
|
|
|
|
|
[section `mp_valid<F, T...>`]
|
|
|
|
|
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.
|
|
|
|
|
[endsect]
|
|
|
|
|
|
|
|
|
|
[section `mp_defer<F, T...>`]
|
|
|
|
|
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.
|
|
|
|
|
[endsect]
|
|
|
|
|
|
2017-05-12 19:43:03 +03:00
|
|
|
[section `mp_quote<F>`]
|
|
|
|
|
template<template<class...> class F> struct mp_quote
|
2017-03-14 22:57:07 +02:00
|
|
|
{
|
2017-05-12 19:43:03 +03:00
|
|
|
template<class... T> using fn = F<T...>;
|
2017-03-14 22:57:07 +02:00
|
|
|
};
|
|
|
|
|
|
2017-05-12 19:43:03 +03: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
|
|
|
[endsect]
|
|
|
|
|
|
2017-03-17 01:39:52 +02:00
|
|
|
[section `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
|
|
|
|
2017-05-12 19:43:03 +03:00
|
|
|
`mp_invoke<Q, T...>` evaluates the nested template `fn` of a quoted metafunction. `mp_invoke<mp_quote<F>, T...>` returns `F<T...>`.
|
2017-03-14 22:57:07 +02:00
|
|
|
[endsect]
|
|
|
|
|
|
2017-05-12 19:49:05 +03:00
|
|
|
[endsect:utility]
|