forked from boostorg/mp11
Rename Q::apply to Q::invoke, mp_unquote to mp_invoke.
This commit is contained in:
@@ -64,17 +64,17 @@ When `mp_valid<F, T...>` is `mp_true`, `mp_defer<F, T...>` is a struct with a ne
|
|||||||
[section `mp_quote<F, T...>`]
|
[section `mp_quote<F, T...>`]
|
||||||
template<template<class...> class F, class... T> struct mp_quote
|
template<template<class...> class F, class... T> struct mp_quote
|
||||||
{
|
{
|
||||||
template<class... U> using apply = F<T..., U...>;
|
template<class... U> using invoke = F<T..., U...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
`mp_quote<F, T...>` transforms the template `F` into a type. In the common case `mp_quote<F>`, the nested template `apply` of the result is an alias for `F`;
|
`mp_quote<F, T...>` transforms the template `F` into a type. In the common case `mp_quote<F>`, the nested template `invoke` of the result is an alias for `F`;
|
||||||
otherwise, `apply<U...>` is an alias for `F<T..., U...>`, allowing partial application.
|
otherwise, `invoke<U...>` is an alias for `F<T..., U...>`, allowing partial application.
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[section `mp_unquote<Q, T...>`]
|
[section `mp_unquote<Q, T...>`]
|
||||||
template<class Q, class... T> using mp_unquote = typename Q::template apply<T...>;
|
template<class Q, class... T> using mp_unquote = typename Q::template invoke<T...>;
|
||||||
|
|
||||||
`mp_unquote<Q, T...>` evaluates the nested template `apply` of a quoted metafunction. `mp_unquote<mp_quote<F>, T...>` is an alias for `F<T...>`. `mp_unquote<mp_quote<F, T...>, U...>` is an alias for `F<T..., U...>`.
|
`mp_unquote<Q, T...>` evaluates the nested template `invoke` of a quoted metafunction. `mp_unquote<mp_quote<F>, T...>` is an alias for `F<T...>`. `mp_unquote<mp_quote<F, T...>, U...>` is an alias for `F<T..., U...>`.
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
@@ -106,26 +106,26 @@ template<template<class...> class F, class... T> using mp_defer = mp_if<mp_valid
|
|||||||
// mp_quote
|
// mp_quote
|
||||||
template<template<class...> class F, class... T> struct mp_quote
|
template<template<class...> class F, class... T> struct mp_quote
|
||||||
{
|
{
|
||||||
template<class... U> using apply = F<T..., U...>;
|
template<class... U> using invoke = F<T..., U...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
// mp_unquote
|
// mp_unquote
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
template<class Q, class... T> struct mp_unquote_impl
|
template<class Q, class... T> struct mp_invoke_impl
|
||||||
{
|
{
|
||||||
using type = typename Q::template apply<T...>;
|
using type = typename Q::template invoke<T...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<template<class...> class F, class... T, class... U> struct mp_unquote_impl<mp_quote<F, T...>, U...>
|
template<template<class...> class F, class... T, class... U> struct mp_invoke_impl<mp_quote<F, T...>, U...>
|
||||||
{
|
{
|
||||||
using type = F<T..., U...>;
|
using type = F<T..., U...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template<class Q, class... T> using mp_unquote = typename detail::mp_unquote_impl<Q, T...>::type;
|
template<class Q, class... T> using mp_invoke = typename detail::mp_invoke_impl<Q, T...>::type;
|
||||||
|
|
||||||
} // namespace mp11
|
} // namespace mp11
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
@@ -69,6 +69,7 @@ run mp_eval_if.cpp : : : $(REQ) ;
|
|||||||
run mp_valid.cpp : : : $(REQ) ;
|
run mp_valid.cpp : : : $(REQ) ;
|
||||||
run mp_defer.cpp : : : $(REQ) ;
|
run mp_defer.cpp : : : $(REQ) ;
|
||||||
run mp_quote.cpp : : : $(REQ) ;
|
run mp_quote.cpp : : : $(REQ) ;
|
||||||
|
run mp_invoke.cpp : : : $(REQ) ;
|
||||||
|
|
||||||
# integer_sequence
|
# integer_sequence
|
||||||
run integer_sequence.cpp : : : $(REQ) ;
|
run integer_sequence.cpp : : : $(REQ) ;
|
||||||
|
56
test/mp_invoke.cpp
Normal file
56
test/mp_invoke.cpp
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
|
||||||
|
// 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 invoke = void;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Q2
|
||||||
|
{
|
||||||
|
template<class...> class invoke;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Q3
|
||||||
|
{
|
||||||
|
template<class... T> using invoke = mp_size_t<sizeof...(T)>;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Q4
|
||||||
|
{
|
||||||
|
template<class T1, class... T> using invoke = T1;
|
||||||
|
};
|
||||||
|
|
||||||
|
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::invoke<>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q2, int>, Q2::invoke<int>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q2, int[], char[]>, Q2::invoke<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[]>));
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
// Copyright 2015 Peter Dimov.
|
// Copyright 2015, 2017 Peter Dimov.
|
||||||
//
|
//
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
//
|
//
|
||||||
@@ -11,13 +11,13 @@
|
|||||||
#include <boost/core/lightweight_test_trait.hpp>
|
#include <boost/core/lightweight_test_trait.hpp>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
using boost::mp11::mp_unquote;
|
using boost::mp11::mp_invoke;
|
||||||
|
|
||||||
template<class...> struct X {};
|
template<class...> struct X {};
|
||||||
|
|
||||||
template<template<class...> class F, class... T> using Y = X<F<T>...>;
|
template<template<class...> class F, class... T> using Y = X<F<T>...>;
|
||||||
|
|
||||||
template<class Q, class... T> using Z = X<mp_unquote<Q, T>...>;
|
template<class Q, class... T> using Z = X<mp_invoke<Q, T>...>;
|
||||||
|
|
||||||
struct B {};
|
struct B {};
|
||||||
struct D1: B {};
|
struct D1: B {};
|
||||||
@@ -34,27 +34,27 @@ int main()
|
|||||||
{
|
{
|
||||||
using Q = mp_quote<mp_identity_t>;
|
using Q = mp_quote<mp_identity_t>;
|
||||||
|
|
||||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unquote<Q, void>, void>));
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, void>, void>));
|
||||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unquote<Q, int[]>, int[]>));
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, int[]>, int[]>));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
using Q = mp_quote<std::is_same, void>;
|
using Q = mp_quote<std::is_same, void>;
|
||||||
|
|
||||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unquote<Q, void>, std::is_same<void, void>>));
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, void>, std::is_same<void, void>>));
|
||||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unquote<Q, int[]>, std::is_same<void, int[]>>));
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, int[]>, std::is_same<void, int[]>>));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
using Q = mp_quote<X, char[1], char[2], char[3]>;
|
using Q = mp_quote<X, char[1], char[2], char[3]>;
|
||||||
|
|
||||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unquote<Q, int[1], int[2], int[3]>, X<char[1], char[2], char[3], int[1], int[2], int[3]>>));
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_invoke<Q, int[1], int[2], int[3]>, X<char[1], char[2], char[3], int[1], int[2], int[3]>>));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
using Q = mp_quote<mp_identity_t>;
|
using Q = mp_quote<mp_identity_t>;
|
||||||
|
|
||||||
// using R1 = Y<Q::template apply, void, char, int>;
|
// using R1 = Y<Q::template invoke, void, char, int>;
|
||||||
// BOOST_TEST_TRAIT_TRUE((std::is_same<R1, X<void, char, int>>));
|
// BOOST_TEST_TRAIT_TRUE((std::is_same<R1, X<void, char, int>>));
|
||||||
//
|
//
|
||||||
// error: pack expansion used as argument for non-pack parameter of alias template
|
// error: pack expansion used as argument for non-pack parameter of alias template
|
||||||
@@ -71,7 +71,7 @@ int main()
|
|||||||
|
|
||||||
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 )
|
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 )
|
||||||
#else
|
#else
|
||||||
using R1 = Y<Q::template apply, D1, D2, ND, int>;
|
using R1 = Y<Q::template invoke, D1, D2, ND, int>;
|
||||||
BOOST_TEST_TRAIT_TRUE((std::is_same<R1, X<std::true_type, std::true_type, std::false_type, std::false_type>>));
|
BOOST_TEST_TRAIT_TRUE((std::is_same<R1, X<std::true_type, std::true_type, std::false_type, std::false_type>>));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user