forked from boostorg/mp11
Add mp_replace_at(_c)
This commit is contained in:
@@ -834,6 +834,25 @@ template<class L, template<class...> class P> using mp_none_of = mp_bool< mp_cou
|
||||
// mp_any_of<L, P>
|
||||
template<class L, template<class...> class P> using mp_any_of = mp_bool< mp_count_if<L, P>::value != 0 >;
|
||||
|
||||
// mp_replace_at_c<L, I, W>
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class L, class I, class W> struct mp_replace_at_impl
|
||||
{
|
||||
static_assert( I::value >= 0, "mp_replace_at<L, I, W>: I must not be negative" );
|
||||
|
||||
template<class T1, class T2> using _p = std::is_same<T2, mp_size_t<I::value>>;
|
||||
template<class T1, class T2> using _f = W;
|
||||
|
||||
using type = mp_transform_if<_p, _f, L, mp_iota<mp_size<L>>>;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class L, class I, class W> using mp_replace_at = typename detail::mp_replace_at_impl<L, I, W>::type;
|
||||
template<class L, std::size_t I, class W> using mp_replace_at_c = typename detail::mp_replace_at_impl<L, mp_size_t<I>, W>::type;
|
||||
|
||||
} // namespace mp11
|
||||
} // namespace boost
|
||||
|
||||
|
@@ -60,6 +60,8 @@ run mp_unique.cpp : : : $(REQ) ;
|
||||
run mp_all_of.cpp : : : $(REQ) ;
|
||||
run mp_any_of.cpp : : : $(REQ) ;
|
||||
run mp_none_of.cpp : : : $(REQ) ;
|
||||
run mp_replace_at.cpp : : : $(REQ) ;
|
||||
run mp_replace_at_c.cpp : : : $(REQ) ;
|
||||
|
||||
# integral
|
||||
run integral.cpp : : : $(REQ) ;
|
||||
|
60
test/mp_replace_at.cpp
Normal file
60
test/mp_replace_at.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
// Copyright 2015, 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/list.hpp>
|
||||
#include <boost/mp11/integral.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
struct X1 {};
|
||||
struct X2 {};
|
||||
struct X3 {};
|
||||
struct X4 {};
|
||||
struct X5 {};
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp11::mp_list;
|
||||
using boost::mp11::mp_replace_at;
|
||||
using boost::mp11::mp_int;
|
||||
using boost::mp11::mp_true;
|
||||
using boost::mp11::mp_false;
|
||||
|
||||
{
|
||||
using L = mp_list<X1, X2, X3, X4, X5>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<0>, void>, mp_list<void, X2, X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<1>, void>, mp_list<X1, void, X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<2>, void>, mp_list<X1, X2, void, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<3>, void>, mp_list<X1, X2, X3, void, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<4>, void>, mp_list<X1, X2, X3, X4, void>>));
|
||||
}
|
||||
|
||||
{
|
||||
using L = std::tuple<X1, X2, X3, X4, X5>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<0>, void>, std::tuple<void, X2, X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<1>, void>, std::tuple<X1, void, X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<2>, void>, std::tuple<X1, X2, void, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<3>, void>, std::tuple<X1, X2, X3, void, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_int<4>, void>, std::tuple<X1, X2, X3, X4, void>>));
|
||||
}
|
||||
|
||||
{
|
||||
using L = std::pair<X1, X2>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_false, void>, std::pair<void, X2>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at<L, mp_true, void>, std::pair<X1, void>>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
56
test/mp_replace_at_c.cpp
Normal file
56
test/mp_replace_at_c.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
// Copyright 2015, 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/list.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
struct X1 {};
|
||||
struct X2 {};
|
||||
struct X3 {};
|
||||
struct X4 {};
|
||||
struct X5 {};
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp11::mp_list;
|
||||
using boost::mp11::mp_replace_at_c;
|
||||
|
||||
{
|
||||
using L = mp_list<X1, X2, X3, X4, X5>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at_c<L, 0, void>, mp_list<void, X2, X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at_c<L, 1, void>, mp_list<X1, void, X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at_c<L, 2, void>, mp_list<X1, X2, void, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at_c<L, 3, void>, mp_list<X1, X2, X3, void, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at_c<L, 4, void>, mp_list<X1, X2, X3, X4, void>>));
|
||||
}
|
||||
|
||||
{
|
||||
using L = std::tuple<X1, X2, X3, X4, X5>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at_c<L, 0, void>, std::tuple<void, X2, X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at_c<L, 1, void>, std::tuple<X1, void, X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at_c<L, 2, void>, std::tuple<X1, X2, void, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at_c<L, 3, void>, std::tuple<X1, X2, X3, void, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at_c<L, 4, void>, std::tuple<X1, X2, X3, X4, void>>));
|
||||
}
|
||||
|
||||
{
|
||||
using L = std::pair<X1, X2>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at_c<L, 0, void>, std::pair<void, X2>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_at_c<L, 1, void>, std::pair<X1, void>>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user