forked from boostorg/mp11
Add support for value lists to mp_replace_first, mp_replace_second, mp_replace_third. Refs #53.
This commit is contained in:
@@ -299,6 +299,15 @@ template<template<class...> class L, class U1, class... U, class T> struct mp_re
|
|||||||
using type = L<T, U...>;
|
using type = L<T, U...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
|
||||||
|
|
||||||
|
template<template<auto...> class L, auto A1, auto... A, class T> struct mp_replace_front_impl<L<A1, A...>, T>
|
||||||
|
{
|
||||||
|
using type = L<T::value, A...>;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template<class L, class T> using mp_replace_front = typename detail::mp_replace_front_impl<L, T>::type;
|
template<class L, class T> using mp_replace_front = typename detail::mp_replace_front_impl<L, T>::type;
|
||||||
@@ -321,6 +330,15 @@ template<template<class...> class L, class U1, class U2, class... U, class T> st
|
|||||||
using type = L<U1, T, U...>;
|
using type = L<U1, T, U...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
|
||||||
|
|
||||||
|
template<template<auto...> class L, auto A1, auto A2, auto... A, class T> struct mp_replace_second_impl<L<A1, A2, A...>, T>
|
||||||
|
{
|
||||||
|
using type = L<A1, T::value, A...>;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template<class L, class T> using mp_replace_second = typename detail::mp_replace_second_impl<L, T>::type;
|
template<class L, class T> using mp_replace_second = typename detail::mp_replace_second_impl<L, T>::type;
|
||||||
@@ -340,6 +358,15 @@ template<template<class...> class L, class U1, class U2, class U3, class... U, c
|
|||||||
using type = L<U1, U2, T, U...>;
|
using type = L<U1, U2, T, U...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
|
||||||
|
|
||||||
|
template<template<auto...> class L, auto A1, auto A2, auto A3, auto... A, class T> struct mp_replace_third_impl<L<A1, A2, A3, A...>, T>
|
||||||
|
{
|
||||||
|
using type = L<A1, A2, T::value, A...>;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template<class L, class T> using mp_replace_third = typename detail::mp_replace_third_impl<L, T>::type;
|
template<class L, class T> using mp_replace_third = typename detail::mp_replace_third_impl<L, T>::type;
|
||||||
|
@@ -51,8 +51,11 @@ run mp_append.cpp ;
|
|||||||
run mp_append_2.cpp ;
|
run mp_append_2.cpp ;
|
||||||
run mp_append_sf.cpp ;
|
run mp_append_sf.cpp ;
|
||||||
run mp_replace_front.cpp ;
|
run mp_replace_front.cpp ;
|
||||||
|
run mp_replace_front_2.cpp ;
|
||||||
run mp_replace_second.cpp ;
|
run mp_replace_second.cpp ;
|
||||||
|
run mp_replace_second_2.cpp ;
|
||||||
run mp_replace_third.cpp ;
|
run mp_replace_third.cpp ;
|
||||||
|
run mp_replace_third_2.cpp ;
|
||||||
run mp_apply_q.cpp ;
|
run mp_apply_q.cpp ;
|
||||||
run mp_apply_q_sf.cpp ;
|
run mp_apply_q_sf.cpp ;
|
||||||
run mp_is_list.cpp ;
|
run mp_is_list.cpp ;
|
||||||
|
60
test/mp_replace_front_2.cpp
Normal file
60
test/mp_replace_front_2.cpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
// Copyright 2023 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/mp11/list.hpp>
|
||||||
|
|
||||||
|
#if !defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
|
||||||
|
|
||||||
|
#pragma message("Test skipped because BOOST_MP11_HAS_TEMPLATE_AUTO is not defined")
|
||||||
|
int main() {}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <boost/mp11/integral.hpp>
|
||||||
|
#include <boost/core/lightweight_test_trait.hpp>
|
||||||
|
|
||||||
|
template<auto... A> struct L1 {};
|
||||||
|
template<int... I> struct L2 {};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
using boost::mp11::mp_replace_front;
|
||||||
|
using boost::mp11::mp_replace_first;
|
||||||
|
using boost::mp11::mp_size_t;
|
||||||
|
using boost::mp11::mp_int;
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_front<L1<0>, mp_size_t<0>>, L1<std::size_t(0)>);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_first<L1<0>, mp_size_t<0>>, L1<std::size_t(0)>);
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_front<L1<0, 1>, mp_size_t<0>>, L1<std::size_t(0), 1>);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_first<L1<0, 1>, mp_size_t<0>>, L1<std::size_t(0), 1>);
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_front<L1<0, 1, false>, mp_size_t<0>>, L1<std::size_t(0), 1, false>);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_first<L1<0, 1, false>, mp_size_t<0>>, L1<std::size_t(0), 1, false>);
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_front<L1<0, 1, false, true>, mp_size_t<0>>, L1<std::size_t(0), 1, false, true>);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_first<L1<0, 1, false, true>, mp_size_t<0>>, L1<std::size_t(0), 1, false, true>);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_front<L2<0>, mp_int<-1>>, L2<-1>);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_first<L2<0>, mp_int<-1>>, L2<-1>);
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_front<L2<0, 1>, mp_int<-1>>, L2<-1, 1>);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_first<L2<0, 1>, mp_int<-1>>, L2<-1, 1>);
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_front<L2<0, 1, 2>, mp_int<-1>>, L2<-1, 1, 2>);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_first<L2<0, 1, 2>, mp_int<-1>>, L2<-1, 1, 2>);
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_front<L2<0, 1, 2, 3>, mp_int<-1>>, L2<-1, 1, 2, 3>);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_first<L2<0, 1, 2, 3>, mp_int<-1>>, L2<-1, 1, 2, 3>);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
43
test/mp_replace_second_2.cpp
Normal file
43
test/mp_replace_second_2.cpp
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
// Copyright 2023 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/mp11/list.hpp>
|
||||||
|
|
||||||
|
#if !defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
|
||||||
|
|
||||||
|
#pragma message("Test skipped because BOOST_MP11_HAS_TEMPLATE_AUTO is not defined")
|
||||||
|
int main() {}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <boost/mp11/integral.hpp>
|
||||||
|
#include <boost/core/lightweight_test_trait.hpp>
|
||||||
|
|
||||||
|
template<auto... A> struct L1 {};
|
||||||
|
template<int... I> struct L2 {};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
using boost::mp11::mp_replace_second;
|
||||||
|
using boost::mp11::mp_size_t;
|
||||||
|
using boost::mp11::mp_int;
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_second<L1<0, 1>, mp_size_t<0>>, L1<0, std::size_t(0)>);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_second<L1<0, 1, false>, mp_size_t<0>>, L1<0, std::size_t(0), false>);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_second<L1<0, 1, false, true>, mp_size_t<0>>, L1<0, std::size_t(0), false, true>);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_second<L2<0, 1>, mp_int<-1>>, L2<0, -1>);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_second<L2<0, 1, 2>, mp_int<-1>>, L2<0, -1, 2>);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_second<L2<0, 1, 2, 3>, mp_int<-1>>, L2<0, -1, 2, 3>);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
41
test/mp_replace_third_2.cpp
Normal file
41
test/mp_replace_third_2.cpp
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
// Copyright 2023 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/mp11/list.hpp>
|
||||||
|
|
||||||
|
#if !defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
|
||||||
|
|
||||||
|
#pragma message("Test skipped because BOOST_MP11_HAS_TEMPLATE_AUTO is not defined")
|
||||||
|
int main() {}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <boost/mp11/integral.hpp>
|
||||||
|
#include <boost/core/lightweight_test_trait.hpp>
|
||||||
|
|
||||||
|
template<auto... A> struct L1 {};
|
||||||
|
template<int... I> struct L2 {};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
using boost::mp11::mp_replace_third;
|
||||||
|
using boost::mp11::mp_size_t;
|
||||||
|
using boost::mp11::mp_int;
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_third<L1<0, 1, false>, mp_size_t<0>>, L1<0, 1, std::size_t(0)>);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_third<L1<0, 1, false, true>, mp_size_t<0>>, L1<0, 1, std::size_t(0), true>);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_third<L2<0, 1, 2>, mp_int<-1>>, L2<0, 1, -1>);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_replace_third<L2<0, 1, 2, 3>, mp_int<-1>>, L2<0, 1, -1, 3>);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user