forked from boostorg/mp11
Merge pull request #85 from k3DW/develop
Move `mp_slice_c` and `mp_slice` into the public API
This commit is contained in:
@@ -414,6 +414,28 @@ Supports a value list as `L` under {cpp}17.
|
||||
|
||||
Same as `mp_take_c`, but with a type argument `N`. `N::value` must be a nonnegative number.
|
||||
|
||||
## mp_slice_c<L, I, J>
|
||||
|
||||
template<class L, std::size_t I, std::size_t J> using mp_slice_c = mp_drop_c<mp_take_c<L, J>, I>;
|
||||
|
||||
`mp_slice_c<L, I, J>` returns a list of the same form as `L` containing the elements from index `I` (inclusive) to index `J` (exclusive).
|
||||
|
||||
Supports a value list as `L` under {cpp}17.
|
||||
|
||||
.mp_slice_c
|
||||
[cols="<.^4m,8*^.^1m",width=85%]
|
||||
|===
|
||||
|*L1*|A~0~|...|A~i~|...|A~j-1~|A~j~|...|A~n-1~
|
||||
9+|
|
||||
|*mp_slice_c<L1, I, J>* 2+>||A~i~|...|A~j-1~ 3+|
|
||||
|===
|
||||
|
||||
## mp_slice<L, I, J>
|
||||
|
||||
template<class L, class I, class J> using mp_slice = mp_drop<mp_take<L, J>, I>;
|
||||
|
||||
Same as `mp_slice_c`, but with type arguments `I` and `J`. `I::value` and `J::value` must be nonnegative numbers.
|
||||
|
||||
## mp_back<L>
|
||||
|
||||
template<class L> using mp_back = mp_at_c<L, mp_size<L>::value - 1>;
|
||||
|
@@ -473,6 +473,10 @@ struct mp_take_c_impl<N, L<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T...>, typen
|
||||
template<class L, std::size_t N> using mp_take_c = mp_assign<L, typename detail::mp_take_c_impl<N, mp_rename<L, mp_list>>::type>;
|
||||
template<class L, class N> using mp_take = mp_take_c<L, std::size_t{ N::value }>;
|
||||
|
||||
// mp_slice(_c)<L, I, J>
|
||||
template<class L, std::size_t I, std::size_t J> using mp_slice_c = mp_drop_c< mp_take_c<L, J>, I >;
|
||||
template<class L, class I, class J> using mp_slice = mp_drop< mp_take<L, J>, I >;
|
||||
|
||||
// mp_back<L>
|
||||
template<class L> using mp_back = mp_at_c<L, mp_size<L>::value - 1>;
|
||||
|
||||
@@ -1265,9 +1269,6 @@ template<class L, template<class...> class F> using mp_pairwise_fold = mp_pairwi
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class L, std::size_t I, std::size_t J> using mp_slice_c = mp_drop_c< mp_take_c<L, J>, I >;
|
||||
template<class L, class I, class J> using mp_slice = mp_drop< mp_take<L, J>, I >;
|
||||
|
||||
template<class C, class L, class Q, class S> struct mp_sliding_fold_impl;
|
||||
|
||||
template<class L, class N, class Q> struct mp_sliding_fold_impl<mp_true, L, N, Q>
|
||||
|
@@ -99,6 +99,7 @@ run mp_at_2.cpp ;
|
||||
run mp_at_sf.cpp : : : <toolset>gcc-4.7:<warnings>all ;
|
||||
run mp_take.cpp ;
|
||||
run mp_take_2.cpp ;
|
||||
run mp_slice.cpp ;
|
||||
run mp_replace.cpp ;
|
||||
run mp_replace_if.cpp ;
|
||||
run mp_replace_if_q.cpp ;
|
||||
|
118
test/mp_slice.cpp
Normal file
118
test/mp_slice.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
// Copyright 2023 Braden Ganetsky (braden.ganetsky@gmail.com)
|
||||
//
|
||||
// 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/core/lightweight_test_trait.hpp>
|
||||
#include <boost/mp11/algorithm.hpp>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp11::mp_list;
|
||||
using boost::mp11::mp_size_t;
|
||||
using boost::mp11::mp_slice_c;
|
||||
using boost::mp11::mp_slice;
|
||||
|
||||
{
|
||||
using L1 = mp_list<int[], void, float&, char, bool*>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 0, 0>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 0, 1>, mp_list<int[]>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 0, 2>, mp_list<int[], void>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 0, 3>, mp_list<int[], void, float&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 0, 4>, mp_list<int[], void, float&, char>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 0, 5>, mp_list<int[], void, float&, char, bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 1, 1>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 1, 2>, mp_list<void>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 1, 3>, mp_list<void, float&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 1, 4>, mp_list<void, float&, char>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 1, 5>, mp_list<void, float&, char, bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 2, 2>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 2, 3>, mp_list<float&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 2, 4>, mp_list<float&, char>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 2, 5>, mp_list<float&, char, bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 3, 3>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 3, 4>, mp_list<char>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 3, 5>, mp_list<char, bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 4, 4>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 4, 5>, mp_list<bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L1, 5, 5>, mp_list<>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<0>, mp_size_t<0>>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<0>, mp_size_t<1>>, mp_list<int[]>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<0>, mp_size_t<2>>, mp_list<int[], void>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<0>, mp_size_t<3>>, mp_list<int[], void, float&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<0>, mp_size_t<4>>, mp_list<int[], void, float&, char>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<0>, mp_size_t<5>>, mp_list<int[], void, float&, char, bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<1>, mp_size_t<1>>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<1>, mp_size_t<2>>, mp_list<void>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<1>, mp_size_t<3>>, mp_list<void, float&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<1>, mp_size_t<4>>, mp_list<void, float&, char>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<1>, mp_size_t<5>>, mp_list<void, float&, char, bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<2>, mp_size_t<2>>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<2>, mp_size_t<3>>, mp_list<float&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<2>, mp_size_t<4>>, mp_list<float&, char>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<2>, mp_size_t<5>>, mp_list<float&, char, bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<3>, mp_size_t<3>>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<3>, mp_size_t<4>>, mp_list<char>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<3>, mp_size_t<5>>, mp_list<char, bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<4>, mp_size_t<4>>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<4>, mp_size_t<5>>, mp_list<bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L1, mp_size_t<5>, mp_size_t<5>>, mp_list<>>));
|
||||
}
|
||||
|
||||
{
|
||||
using L2 = std::tuple<int[], void, float&, char, bool*>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 0, 0>, std::tuple<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 0, 1>, std::tuple<int[]>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 0, 2>, std::tuple<int[], void>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 0, 3>, std::tuple<int[], void, float&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 0, 4>, std::tuple<int[], void, float&, char>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 0, 5>, std::tuple<int[], void, float&, char, bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 1, 1>, std::tuple<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 1, 2>, std::tuple<void>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 1, 3>, std::tuple<void, float&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 1, 4>, std::tuple<void, float&, char>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 1, 5>, std::tuple<void, float&, char, bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 2, 2>, std::tuple<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 2, 3>, std::tuple<float&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 2, 4>, std::tuple<float&, char>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 2, 5>, std::tuple<float&, char, bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 3, 3>, std::tuple<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 3, 4>, std::tuple<char>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 3, 5>, std::tuple<char, bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 4, 4>, std::tuple<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 4, 5>, std::tuple<bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice_c<L2, 5, 5>, std::tuple<>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<0>, mp_size_t<0>>, std::tuple<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<0>, mp_size_t<1>>, std::tuple<int[]>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<0>, mp_size_t<2>>, std::tuple<int[], void>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<0>, mp_size_t<3>>, std::tuple<int[], void, float&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<0>, mp_size_t<4>>, std::tuple<int[], void, float&, char>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<0>, mp_size_t<5>>, std::tuple<int[], void, float&, char, bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<1>, mp_size_t<1>>, std::tuple<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<1>, mp_size_t<2>>, std::tuple<void>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<1>, mp_size_t<3>>, std::tuple<void, float&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<1>, mp_size_t<4>>, std::tuple<void, float&, char>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<1>, mp_size_t<5>>, std::tuple<void, float&, char, bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<2>, mp_size_t<2>>, std::tuple<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<2>, mp_size_t<3>>, std::tuple<float&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<2>, mp_size_t<4>>, std::tuple<float&, char>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<2>, mp_size_t<5>>, std::tuple<float&, char, bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<3>, mp_size_t<3>>, std::tuple<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<3>, mp_size_t<4>>, std::tuple<char>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<3>, mp_size_t<5>>, std::tuple<char, bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<4>, mp_size_t<4>>, std::tuple<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<4>, mp_size_t<5>>, std::tuple<bool*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_slice<L2, mp_size_t<5>, mp_size_t<5>>, std::tuple<>>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user