diff --git a/include/boost/mp11/utility.hpp b/include/boost/mp11/utility.hpp index 38989f4..1b268fa 100644 --- a/include/boost/mp11/utility.hpp +++ b/include/boost/mp11/utility.hpp @@ -1,7 +1,7 @@ #ifndef BOOST_MP11_UTILITY_HPP_INCLUDED #define BOOST_MP11_UTILITY_HPP_INCLUDED -// Copyright 2015, 2017, 2019 Peter Dimov. +// Copyright 2015-2020 Peter Dimov. // // Distributed under the Boost Software License, Version 1.0. // @@ -9,6 +9,8 @@ // http://www.boost.org/LICENSE_1_0.txt #include +#include +#include #include namespace boost @@ -230,6 +232,32 @@ template class P> struct mp_not_fn template using mp_not_fn_q = mp_not_fn; +// mp_compose +namespace detail +{ + +template using mp_reverse_invoke_q = mp_invoke_q; + +} // namespace detail + +#if !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 ) + +template class... F> struct mp_compose +{ + template using fn = mp_fold...>, T, detail::mp_reverse_invoke_q>; +}; + +template using mp_compose_q = mp_compose; + +#else + +template struct mp_compose_q +{ + template using fn = mp_fold, T, detail::mp_reverse_invoke_q>; +}; + +#endif + } // namespace mp11 } // namespace boost diff --git a/test/Jamfile b/test/Jamfile index d242273..4ccab62 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -141,6 +141,7 @@ run mp_cond_sf.cpp ; run mp_not_fn.cpp ; run mp_eval_if_not.cpp ; run mp_eval_or.cpp ; +run mp_compose.cpp ; # integer_sequence run integer_sequence.cpp ; diff --git a/test/mp_compose.cpp b/test/mp_compose.cpp new file mode 100644 index 0000000..46184a6 --- /dev/null +++ b/test/mp_compose.cpp @@ -0,0 +1,59 @@ + +// Copyright 2017, 2020 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + + +#include +#include + +template struct F1 {}; +template struct F2 {}; +template struct F3 {}; + +template using G1 = F1; +template using G2 = F2; +template using G3 = F3; + +int main() +{ + using namespace boost::mp11; + +#if !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 ) + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, void>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, F1>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, F1>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, F2>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, F2>>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, F3>>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, F3>>>)); + +#endif + + using QF1 = mp_quote; + using QF2 = mp_quote; + using QF3 = mp_quote; + + using QG1 = mp_quote; + using QG2 = mp_quote; + using QG3 = mp_quote; + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, void>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, F1>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, F1>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, F2>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, F2>>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, F3>>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, F3>>>)); + + // + + return boost::report_errors(); +}