forked from boostorg/mp11
Add mp_list_c, mp_from_sequence
This commit is contained in:
@ -297,6 +297,17 @@ As `mp_product`, but takes a quoted metafunction.
|
||||
|
||||
Same as `mp_drop_c`, but with a type argument `N`. `N::value` must be a nonnegative number.
|
||||
|
||||
## mp_from_sequence<S>
|
||||
|
||||
template<class S> using mp_from_sequence = /*...*/
|
||||
|
||||
`mp_from_sequence` transforms an integer sequence produced by `make_integer_sequence` into an `mp_list`
|
||||
of the corresponding `std::integral_constant` types. Given
|
||||
|
||||
template<class T, class... I> struct S;
|
||||
|
||||
`mp_from_sequence<S<T, I...>>` is an alias for `mp_list<std::integral_constant<T, I>...>`.
|
||||
|
||||
## mp_iota_c<N>
|
||||
|
||||
template<std::size_t N> using mp_iota_c = /*...*/;
|
||||
|
@ -21,6 +21,18 @@ http://www.boost.org/LICENSE_1_0.txt
|
||||
such as `std::tuple` or `std::variant`. Even `std::pair` can be used if the transformation does not alter the number of the elements in
|
||||
the list.
|
||||
|
||||
## mp_list_c<T, I...>
|
||||
|
||||
template<class T, T... I> using mp_list_c =
|
||||
mp_list<std::integral_constant<T, I>...>;
|
||||
|
||||
`mp_list_c` produces an `mp_list` of the `std::integral_constant` types corresponding to its integer template arguments.
|
||||
|
||||
.Using mp_list_c
|
||||
```
|
||||
using L1 = mp_list_c<int, 2, 3>; // mp_list<mp_int<2>, mp_int<3>>
|
||||
```
|
||||
|
||||
## mp_is_list<L>
|
||||
|
||||
template<class L> using mp_is_list = /*...*/;
|
||||
|
@ -287,7 +287,7 @@ template<class L, std::size_t N> using mp_drop_c = typename detail::mp_drop_impl
|
||||
|
||||
template<class L, class N> using mp_drop = typename detail::mp_drop_impl<L, mp_repeat<mp_list<void>, N>>::type;
|
||||
|
||||
// mp_iota(_c)<N>
|
||||
// mp_from_sequence<S>
|
||||
namespace detail
|
||||
{
|
||||
|
||||
@ -298,12 +298,13 @@ template<template<class T, T... I> class S, class U, U... J> struct mp_from_sequ
|
||||
using type = mp_list<std::integral_constant<U, J>...>;
|
||||
};
|
||||
|
||||
template<class S> using mp_from_sequence = typename mp_from_sequence_impl<S>::type;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<std::size_t N> using mp_iota_c = detail::mp_from_sequence<make_index_sequence<N>>;
|
||||
template<class N> using mp_iota = detail::mp_from_sequence<make_integer_sequence<typename std::remove_const<decltype(N::value)>::type, N::value>>;
|
||||
template<class S> using mp_from_sequence = typename detail::mp_from_sequence_impl<S>::type;
|
||||
|
||||
// mp_iota(_c)<N>
|
||||
template<std::size_t N> using mp_iota_c = mp_from_sequence<make_index_sequence<N>>;
|
||||
template<class N> using mp_iota = mp_from_sequence<make_integer_sequence<typename std::remove_const<decltype(N::value)>::type, N::value>>;
|
||||
|
||||
// mp_at(_c)<L, I>
|
||||
namespace detail
|
||||
|
@ -13,12 +13,16 @@
|
||||
#include <boost/mp11/detail/mp_append.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace mp11
|
||||
{
|
||||
|
||||
// mp_list_c<T, I...>
|
||||
template<class T, T... I> using mp_list_c = mp_list<std::integral_constant<T, I>...>;
|
||||
|
||||
// mp_is_list<L>
|
||||
namespace detail
|
||||
{
|
||||
|
@ -31,6 +31,7 @@ run mp_replace_second.cpp ;
|
||||
run mp_replace_third.cpp ;
|
||||
run mp_apply_q.cpp ;
|
||||
run mp_is_list.cpp ;
|
||||
run mp_list_c.cpp ;
|
||||
|
||||
# algorithm
|
||||
run mp_assign.cpp ;
|
||||
@ -74,6 +75,7 @@ run mp_insert.cpp ;
|
||||
run mp_erase.cpp ;
|
||||
run mp_with_index.cpp ;
|
||||
run mp_with_index_cx.cpp ;
|
||||
run mp_from_sequence.cpp ;
|
||||
|
||||
# integral
|
||||
run integral.cpp ;
|
||||
|
43
test/mp_from_sequence.cpp
Normal file
43
test/mp_from_sequence.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
// Copyright 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 <boost/mp11/algorithm.hpp>
|
||||
#include <boost/mp11/integral.hpp>
|
||||
#include <boost/mp11/integer_sequence.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
template<class T, T... I> struct S;
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp11::mp_list;
|
||||
using boost::mp11::mp_from_sequence;
|
||||
using boost::mp11::mp_int;
|
||||
using boost::mp11::mp_size_t;
|
||||
using boost::mp11::make_integer_sequence;
|
||||
using boost::mp11::make_index_sequence;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_from_sequence<S<int>>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_from_sequence<S<int, 1>>, mp_list<mp_int<1>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_from_sequence<S<int, 1, 3>>, mp_list<mp_int<1>, mp_int<3>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_from_sequence<S<int, 1, 3, 5>>, mp_list<mp_int<1>, mp_int<3>, mp_int<5>>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_from_sequence<make_integer_sequence<int, 0>>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_from_sequence<make_integer_sequence<int, 1>>, mp_list<mp_int<0>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_from_sequence<make_integer_sequence<int, 2>>, mp_list<mp_int<0>, mp_int<1>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_from_sequence<make_integer_sequence<int, 3>>, mp_list<mp_int<0>, mp_int<1>, mp_int<2>>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_from_sequence<make_index_sequence<0>>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_from_sequence<make_index_sequence<1>>, mp_list<mp_size_t<0>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_from_sequence<make_index_sequence<2>>, mp_list<mp_size_t<0>, mp_size_t<1>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_from_sequence<make_index_sequence<3>>, mp_list<mp_size_t<0>, mp_size_t<1>, mp_size_t<2>>>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
27
test/mp_list_c.cpp
Normal file
27
test/mp_list_c.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
// Copyright 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 <boost/mp11/list.hpp>
|
||||
#include <boost/mp11/integral.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp11::mp_list_c;
|
||||
using boost::mp11::mp_list;
|
||||
using boost::mp11::mp_int;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_list_c<int>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_list_c<int, 1>, mp_list<mp_int<1>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_list_c<int, 1, 3>, mp_list<mp_int<1>, mp_int<3>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_list_c<int, 1, 3, 5>, mp_list<mp_int<1>, mp_int<3>, mp_int<5>>>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user