diff --git a/test/Jamfile b/test/Jamfile index 8c8f683..f8344f6 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -152,6 +152,7 @@ run mp_eval_if_not.cpp ; run mp_eval_or.cpp ; run mp_compose.cpp ; run mp_valid_and_true.cpp ; +compile mp_compose_sf.cpp ; # integer_sequence run integer_sequence.cpp ; diff --git a/test/mp_compose_sf.cpp b/test/mp_compose_sf.cpp new file mode 100644 index 0000000..0db0664 --- /dev/null +++ b/test/mp_compose_sf.cpp @@ -0,0 +1,58 @@ +// Copyright 2023 Jody Hagins +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +using namespace boost::mp11; + +// A simple metafunction that takes the first three items from a list +template +using take3 = mp_take>; + +// Directly call take3 +static_assert(mp_same< + take3>, + mp_list, mp_size_t<1>, mp_size_t<2>>>::value, ""); + +// Invoke a quoted take3 (mp_quote) +static_assert(mp_same< + mp_invoke_q, mp_iota_c<9>>, + mp_list, mp_size_t<1>, mp_size_t<2>>>::value, ""); + +#if !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 ) + +// Invoke a composed take3 (mp_compose) +static_assert(mp_same< + mp_invoke_q, mp_iota_c<9>>, + mp_list, mp_size_t<1>, mp_size_t<2>>>::value, ""); + +#endif + +// If we apply the following iteration, we expect to get all triplets of the list. +using expected = mp_list< + mp_list, mp_size_t<1>, mp_size_t<2>>, + mp_list, mp_size_t<4>, mp_size_t<5>>, + mp_list, mp_size_t<7>, mp_size_t<8>>>; + +// First using mp_quote - this works as expected +static_assert( + mp_same< + mp_iterate_q< + mp_iota_c<9>, + mp_quote, + mp_bind_back>>, + expected>::value, ""); + +#if !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 ) + +// Next, simply replace mp_quote with mp_compose. We expect to get the same answer, +// but we get a hard compiler error instead. +static_assert( + mp_same< + mp_iterate_q< + mp_iota_c<9>, + mp_compose, + mp_bind_back>>, + expected>::value, ""); + +#endif