From 321a54728fcdefbed1b816cbf30323831cdc420d Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 20 Mar 2017 16:55:00 +0200 Subject: [PATCH] Add indirection in mp_quote to enable expansions of T... into a fixed parameter list --- include/boost/mp11/utility.hpp | 11 ++++++++++- test/mp_invoke.cpp | 7 +++++++ test/mp_quote.cpp | 11 ++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/boost/mp11/utility.hpp b/include/boost/mp11/utility.hpp index 2d7d2a1..78b5a9a 100644 --- a/include/boost/mp11/utility.hpp +++ b/include/boost/mp11/utility.hpp @@ -106,7 +106,16 @@ template class F, class... T> using mp_defer = mp_if class F, class... T> struct mp_quote { - template using fn = F; +private: + + template struct _fn { using type = F; }; + +public: + + // the indirection through _fn works around the language inability + // to expand T.. to expand into a fixed parameter list of an alias template + + template using fn = typename _fn::type; }; // mp_unquote diff --git a/test/mp_invoke.cpp b/test/mp_invoke.cpp index e97ca49..766e6bd 100644 --- a/test/mp_invoke.cpp +++ b/test/mp_invoke.cpp @@ -35,6 +35,11 @@ struct Q4 template using fn = T1; }; +struct Q5 +{ + template using fn = T2; +}; + int main() { BOOST_TEST_TRAIT_TRUE((std::is_same, void>)); @@ -52,5 +57,7 @@ int main() BOOST_TEST_TRAIT_TRUE((std::is_same, int>)); BOOST_TEST_TRAIT_TRUE((std::is_same, int[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, float>)); + return boost::report_errors(); } diff --git a/test/mp_quote.cpp b/test/mp_quote.cpp index 3a338d3..29bb317 100644 --- a/test/mp_quote.cpp +++ b/test/mp_quote.cpp @@ -24,7 +24,7 @@ struct D1: B {}; struct D2: B {}; struct ND {}; -template using is_base_of_t = typename std::is_base_of::type; +template using is_base_of_t = typename std::is_base_of::type; int main() { @@ -54,10 +54,11 @@ int main() { using Q = mp_quote; - // using R1 = Y; - // BOOST_TEST_TRAIT_TRUE((std::is_same>)); - // - // error: pack expansion used as argument for non-pack parameter of alias template +#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 ) +#else + using R1 = Y; + BOOST_TEST_TRAIT_TRUE((std::is_same>)); +#endif #if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1910 && BOOST_MSVC >= 1900 ) #else