forked from boostorg/mp11
Rename mp_invoke to mp_invoke_q
This commit is contained in:
@ -206,28 +206,28 @@ using R1 = mp_transform_q<mp_quote_trait<std::add_pointer>, L1>;
|
||||
// mp_list<int*, void*, float*>
|
||||
```
|
||||
|
||||
## mp_invoke<Q, T...>
|
||||
## mp_invoke_q<Q, T...>
|
||||
|
||||
template<class Q, class... T> using mp_invoke = typename Q::template fn<T...>;
|
||||
template<class Q, class... T> using mp_invoke_q = typename Q::template fn<T...>;
|
||||
|
||||
`mp_invoke<Q, T...>` evaluates the nested template `fn` of a quoted metafunction. `mp_invoke<mp_quote<F>, T...>` returns `F<T...>`.
|
||||
`mp_invoke_q<Q, T...>` evaluates the nested template `fn` of a quoted metafunction. `mp_invoke_q<mp_quote<F>, T...>` returns `F<T...>`.
|
||||
|
||||
.Using mp_invoke to invoke a list of metafunctions, technique 1
|
||||
.Using mp_invoke_q to invoke a list of metafunctions, technique 1
|
||||
```
|
||||
using LQ = mp_list<mp_quote<std::is_const>, mp_quote<std::is_volatile>>;
|
||||
|
||||
template<class T> using is_const_and_volatile =
|
||||
mp_all<mp_product<mp_invoke, LQ, mp_list<T>>>;
|
||||
mp_all<mp_product<mp_invoke_q, LQ, mp_list<T>>>;
|
||||
```
|
||||
|
||||
.Using mp_invoke to invoke a list of metafunctions, technique 2
|
||||
.Using mp_invoke_q to invoke a list of metafunctions, technique 2
|
||||
```
|
||||
template<class T> using is_const_and_volatile =
|
||||
mp_all<mp_transform_q<mp_bind_back<mp_invoke, T>, LQ>>;
|
||||
mp_all<mp_transform_q<mp_bind_back<mp_invoke_q, T>, LQ>>;
|
||||
```
|
||||
|
||||
.Using mp_invoke to invoke a list of metafunctions, technique 3
|
||||
.Using mp_invoke_q to invoke a list of metafunctions, technique 3
|
||||
```
|
||||
template<class T> using is_const_and_volatile =
|
||||
mp_all<mp_transform<mp_invoke, LQ, mp_fill<LQ, T>>>;
|
||||
mp_all<mp_transform<mp_invoke_q, LQ, mp_fill<LQ, T>>>;
|
||||
```
|
||||
|
@ -156,12 +156,12 @@ template<template<class...> class P, template<class...> class F, class... L> str
|
||||
|
||||
#if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1920 )
|
||||
|
||||
template<class... U> struct _f_ { using type = mp_eval_if_q<mp_not<mp_invoke<Qp, U...>>, mp_first<mp_list<U...>>, Qf, U...>; };
|
||||
template<class... U> struct _f_ { using type = mp_eval_if_q<mp_not<mp_invoke_q<Qp, U...>>, mp_first<mp_list<U...>>, Qf, U...>; };
|
||||
template<class... U> using _f = typename _f_<U...>::type;
|
||||
|
||||
#else
|
||||
|
||||
template<class... U> using _f = mp_eval_if_q<mp_not<mp_invoke<Qp, U...>>, mp_first<mp_list<U...>>, Qf, U...>;
|
||||
template<class... U> using _f = mp_eval_if_q<mp_not<mp_invoke_q<Qp, U...>>, mp_first<mp_list<U...>>, Qf, U...>;
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -187,25 +187,25 @@ template<template<class...> class F> struct mp_quote_trait
|
||||
template<class... T> using fn = typename F<T...>::type;
|
||||
};
|
||||
|
||||
// mp_invoke
|
||||
// mp_invoke_q
|
||||
#if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 )
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class Q, class... T> struct mp_invoke_impl: mp_defer<Q::template fn, T...> {};
|
||||
template<class Q, class... T> struct mp_invoke_q_impl: mp_defer<Q::template fn, T...> {};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class Q, class... T> using mp_invoke = typename detail::mp_invoke_impl<Q, T...>::type;
|
||||
template<class Q, class... T> using mp_invoke_q = typename detail::mp_invoke_q_impl<Q, T...>::type;
|
||||
|
||||
#elif BOOST_MP11_WORKAROUND( BOOST_MP11_GCC, < 50000 )
|
||||
|
||||
template<class Q, class... T> using mp_invoke = typename mp_defer<Q::template fn, T...>::type;
|
||||
template<class Q, class... T> using mp_invoke_q = typename mp_defer<Q::template fn, T...>::type;
|
||||
|
||||
#else
|
||||
|
||||
template<class Q, class... T> using mp_invoke = typename Q::template fn<T...>;
|
||||
template<class Q, class... T> using mp_invoke_q = typename Q::template fn<T...>;
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -110,8 +110,8 @@ run mp_eval_if_sf.cpp ;
|
||||
run mp_valid.cpp ;
|
||||
run mp_defer.cpp ;
|
||||
run mp_quote.cpp ;
|
||||
run mp_invoke.cpp ;
|
||||
run mp_invoke_sf.cpp ;
|
||||
run mp_invoke_q.cpp ;
|
||||
run mp_invoke_q_sf.cpp ;
|
||||
run mp_quote_trait.cpp ;
|
||||
run mp_cond.cpp ;
|
||||
run mp_cond_sf.cpp ;
|
||||
|
@ -1,63 +0,0 @@
|
||||
|
||||
// Copyright 2015, 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
|
||||
|
||||
|
||||
#include <boost/mp11/utility.hpp>
|
||||
#include <boost/mp11/integral.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
using boost::mp11::mp_invoke;
|
||||
using boost::mp11::mp_size_t;
|
||||
|
||||
struct Q1
|
||||
{
|
||||
template<class...> using fn = void;
|
||||
};
|
||||
|
||||
struct Q2
|
||||
{
|
||||
template<class...> class fn;
|
||||
};
|
||||
|
||||
struct Q3
|
||||
{
|
||||
template<class... T> using fn = mp_size_t<sizeof...(T)>;
|
||||
};
|
||||
|
||||
struct Q4
|
||||
{
|
||||
template<class T1, class... T> using fn = T1;
|
||||
};
|
||||
|
||||
struct Q5
|
||||
{
|
||||
template<class T1, class T2> using fn = T2;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q1>, void>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q1, int>, void>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q1, int[], char[]>, void>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q2>, Q2::fn<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q2, int>, Q2::fn<int>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q2, int[], char[]>, Q2::fn<int[], char[]>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q3>, mp_size_t<0>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q3, int>, mp_size_t<1>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q3, int[], char[]>, mp_size_t<2>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q4, int>, int>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q4, int[], char[]>, int[]>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q5, int, float>, float>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
63
test/mp_invoke_q.cpp
Normal file
63
test/mp_invoke_q.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
|
||||
// Copyright 2015, 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
|
||||
|
||||
|
||||
#include <boost/mp11/utility.hpp>
|
||||
#include <boost/mp11/integral.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
using boost::mp11::mp_invoke_q;
|
||||
using boost::mp11::mp_size_t;
|
||||
|
||||
struct Q1
|
||||
{
|
||||
template<class...> using fn = void;
|
||||
};
|
||||
|
||||
struct Q2
|
||||
{
|
||||
template<class...> class fn;
|
||||
};
|
||||
|
||||
struct Q3
|
||||
{
|
||||
template<class... T> using fn = mp_size_t<sizeof...(T)>;
|
||||
};
|
||||
|
||||
struct Q4
|
||||
{
|
||||
template<class T1, class... T> using fn = T1;
|
||||
};
|
||||
|
||||
struct Q5
|
||||
{
|
||||
template<class T1, class T2> using fn = T2;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q1>, void>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q1, int>, void>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q1, int[], char[]>, void>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q2>, Q2::fn<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q2, int>, Q2::fn<int>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q2, int[], char[]>, Q2::fn<int[], char[]>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q3>, mp_size_t<0>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q3, int>, mp_size_t<1>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q3, int[], char[]>, mp_size_t<2>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q4, int>, int>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q4, int[], char[]>, int[]>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q5, int, float>, float>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
using boost::mp11::mp_invoke;
|
||||
using boost::mp11::mp_invoke_q;
|
||||
using boost::mp11::mp_quote;
|
||||
using boost::mp11::mp_quote_trait;
|
||||
using boost::mp11::mp_valid;
|
||||
@ -21,24 +21,24 @@ using boost::mp11::mp_identity_t;
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_invoke>));
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_invoke, void>));
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_invoke, void, void>));
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_invoke, void, void, void>));
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_invoke_q>));
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_invoke_q, void>));
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_invoke_q, void, void>));
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_invoke_q, void, void, void>));
|
||||
|
||||
using Qi = mp_quote<mp_identity_t>;
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_invoke, Qi>));
|
||||
BOOST_TEST_TRAIT_TRUE((mp_valid<mp_invoke, Qi, void>));
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_invoke, Qi, void, void>));
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_invoke_q, Qi>));
|
||||
BOOST_TEST_TRAIT_TRUE((mp_valid<mp_invoke_q, Qi, void>));
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_invoke_q, Qi, void, void>));
|
||||
|
||||
using Qt = mp_quote_trait<mp_identity>;
|
||||
|
||||
#if !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, <= 1800 )
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_invoke, Qt>));
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_invoke_q, Qt>));
|
||||
#endif
|
||||
BOOST_TEST_TRAIT_TRUE((mp_valid<mp_invoke, Qt, void>));
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_invoke, Qt, void, void>));
|
||||
BOOST_TEST_TRAIT_TRUE((mp_valid<mp_invoke_q, Qt, void>));
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_invoke_q, Qt, void, void>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@ -12,13 +12,13 @@
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
using boost::mp11::mp_invoke;
|
||||
using boost::mp11::mp_invoke_q;
|
||||
|
||||
template<class...> struct X {};
|
||||
|
||||
template<template<class...> class F, class... T> using Y = X<F<T>...>;
|
||||
|
||||
template<class Q, class... T> using Z = X<mp_invoke<Q, T>...>;
|
||||
template<class Q, class... T> using Z = X<mp_invoke_q<Q, T>...>;
|
||||
|
||||
template<class T, class U> struct P {};
|
||||
|
||||
@ -32,8 +32,8 @@ int main()
|
||||
{
|
||||
using Q = mp_quote<mp_identity_t>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, void>, void>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, int[]>, int[]>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q, void>, void>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q, int[]>, int[]>));
|
||||
}
|
||||
|
||||
{
|
||||
@ -53,15 +53,15 @@ int main()
|
||||
{
|
||||
using Q = mp_quote<P>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, void, void>, P<void, void>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, char[], int[]>, P<char[], int[]>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q, void, void>, P<void, void>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q, char[], int[]>, P<char[], int[]>>));
|
||||
}
|
||||
|
||||
{
|
||||
using Q = mp_quote<first>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, void, int>, void>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, char[], int[]>, char[]>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q, void, int>, void>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q, char[], int[]>, char[]>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
|
@ -16,7 +16,7 @@ int main()
|
||||
{
|
||||
using boost::mp11::mp_identity;
|
||||
using boost::mp11::mp_quote_trait;
|
||||
using boost::mp11::mp_invoke;
|
||||
using boost::mp11::mp_invoke_q;
|
||||
|
||||
{
|
||||
using Q = mp_quote_trait<mp_identity>;
|
||||
@ -24,8 +24,8 @@ int main()
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<Q::fn<void>, void>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<Q::fn<int[]>, int[]>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, void>, void>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, int[]>, int[]>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q, void>, void>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q, int[]>, int[]>));
|
||||
}
|
||||
|
||||
{
|
||||
@ -34,8 +34,8 @@ int main()
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<Q::fn<void>, void*>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<Q::fn<int[]>, int(*)[]>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, void>, void*>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, int[]>, int(*)[]>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q, void>, void*>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q, int[]>, int(*)[]>));
|
||||
}
|
||||
|
||||
{
|
||||
@ -48,8 +48,8 @@ int main()
|
||||
|
||||
// g++ 4.7, 4.8 have difficulties with preserving top-level const
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, void>, void const>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, int[]>, int const[]>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q, void>, void const>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke_q<Q, int[]>, int const[]>));
|
||||
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user