From 946937b5ab475722538f1ccafd666b55fda0f27a Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 16 Mar 2017 21:14:42 +0200 Subject: [PATCH] Rename Q::apply to Q::invoke, mp_unquote to mp_invoke. --- doc/mp11/utility.qbk | 10 +++--- include/boost/mp11/utility.hpp | 10 +++--- test/Jamfile.v2 | 1 + test/mp_invoke.cpp | 56 ++++++++++++++++++++++++++++++++++ test/mp_quote.cpp | 20 ++++++------ 5 files changed, 77 insertions(+), 20 deletions(-) create mode 100644 test/mp_invoke.cpp diff --git a/doc/mp11/utility.qbk b/doc/mp11/utility.qbk index b0b4a4b..6f12df0 100644 --- a/doc/mp11/utility.qbk +++ b/doc/mp11/utility.qbk @@ -64,17 +64,17 @@ When `mp_valid` is `mp_true`, `mp_defer` is a struct with a ne [section `mp_quote`] template class F, class... T> struct mp_quote { - template using apply = F; + template using invoke = F; }; -`mp_quote` transforms the template `F` into a type. In the common case `mp_quote`, the nested template `apply` of the result is an alias for `F`; -otherwise, `apply` is an alias for `F`, allowing partial application. +`mp_quote` transforms the template `F` into a type. In the common case `mp_quote`, the nested template `invoke` of the result is an alias for `F`; +otherwise, `invoke` is an alias for `F`, allowing partial application. [endsect] [section `mp_unquote`] - template using mp_unquote = typename Q::template apply; + template using mp_unquote = typename Q::template invoke; -`mp_unquote` evaluates the nested template `apply` of a quoted metafunction. `mp_unquote, T...>` is an alias for `F`. `mp_unquote, U...>` is an alias for `F`. +`mp_unquote` evaluates the nested template `invoke` of a quoted metafunction. `mp_unquote, T...>` is an alias for `F`. `mp_unquote, U...>` is an alias for `F`. [endsect] [endsect] diff --git a/include/boost/mp11/utility.hpp b/include/boost/mp11/utility.hpp index 8ac684c..0f34d3f 100644 --- a/include/boost/mp11/utility.hpp +++ b/include/boost/mp11/utility.hpp @@ -106,26 +106,26 @@ template class F, class... T> using mp_defer = mp_if class F, class... T> struct mp_quote { - template using apply = F; + template using invoke = F; }; // mp_unquote namespace detail { -template struct mp_unquote_impl +template struct mp_invoke_impl { - using type = typename Q::template apply; + using type = typename Q::template invoke; }; -template class F, class... T, class... U> struct mp_unquote_impl, U...> +template class F, class... T, class... U> struct mp_invoke_impl, U...> { using type = F; }; } // namespace detail -template using mp_unquote = typename detail::mp_unquote_impl::type; +template using mp_invoke = typename detail::mp_invoke_impl::type; } // namespace mp11 } // namespace boost diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 2cd6766..29c916b 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -69,6 +69,7 @@ run mp_eval_if.cpp : : : $(REQ) ; run mp_valid.cpp : : : $(REQ) ; run mp_defer.cpp : : : $(REQ) ; run mp_quote.cpp : : : $(REQ) ; +run mp_invoke.cpp : : : $(REQ) ; # integer_sequence run integer_sequence.cpp : : : $(REQ) ; diff --git a/test/mp_invoke.cpp b/test/mp_invoke.cpp new file mode 100644 index 0000000..16ec66e --- /dev/null +++ b/test/mp_invoke.cpp @@ -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 +#include +#include +#include + +using boost::mp11::mp_invoke; +using boost::mp11::mp_size_t; + +struct Q1 +{ + template using invoke = void; +}; + +struct Q2 +{ + template class invoke; +}; + +struct Q3 +{ + template using invoke = mp_size_t; +}; + +struct Q4 +{ + template using invoke = T1; +}; + +int main() +{ + BOOST_TEST_TRAIT_TRUE((std::is_same, void>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, Q2::invoke<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, Q2::invoke>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, Q2::invoke>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<1>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<2>>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, int>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, int[]>)); + + return boost::report_errors(); +} diff --git a/test/mp_quote.cpp b/test/mp_quote.cpp index 26a84af..f05a91f 100644 --- a/test/mp_quote.cpp +++ b/test/mp_quote.cpp @@ -1,5 +1,5 @@ -// Copyright 2015 Peter Dimov. +// Copyright 2015, 2017 Peter Dimov. // // Distributed under the Boost Software License, Version 1.0. // @@ -11,13 +11,13 @@ #include #include -using boost::mp11::mp_unquote; +using boost::mp11::mp_invoke; template struct X {}; template class F, class... T> using Y = X...>; -template using Z = X...>; +template using Z = X...>; struct B {}; struct D1: B {}; @@ -34,27 +34,27 @@ int main() { using Q = mp_quote; - BOOST_TEST_TRAIT_TRUE((std::is_same, void>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, int[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, int[]>)); } { using Q = mp_quote; - BOOST_TEST_TRAIT_TRUE((std::is_same, std::is_same>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, std::is_same>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::is_same>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::is_same>)); } { using Q = mp_quote; - BOOST_TEST_TRAIT_TRUE((std::is_same, X>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, X>)); } { using Q = mp_quote; - // using R1 = Y; + // using R1 = Y; // BOOST_TEST_TRAIT_TRUE((std::is_same>)); // // 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 ) #else - using R1 = Y; + using R1 = Y; BOOST_TEST_TRAIT_TRUE((std::is_same>)); #endif