forked from boostorg/mp11
Add mp_back, mp_pop_back
This commit is contained in:
@ -443,6 +443,12 @@ 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 = typename detail::mp_take_c_impl<N, L>::type;
|
||||
template<class L, class N> using mp_take = typename detail::mp_take_c_impl<std::size_t{ N::value }, L>::type;
|
||||
|
||||
// mp_back<L>
|
||||
template<class L> using mp_back = mp_at_c<L, mp_size<L>::value - 1>;
|
||||
|
||||
// mp_pop_back<L>
|
||||
template<class L> using mp_pop_back = mp_take_c<L, mp_size<L>::value - 1>;
|
||||
|
||||
// mp_replace<L, V, W>
|
||||
namespace detail
|
||||
{
|
||||
|
@ -104,6 +104,8 @@ run mp_max_element.cpp ;
|
||||
run mp_max_element_q.cpp ;
|
||||
run mp_nth_element.cpp ;
|
||||
run mp_nth_element_q.cpp ;
|
||||
run mp_back.cpp ;
|
||||
run mp_pop_back.cpp ;
|
||||
|
||||
# integral
|
||||
run integral.cpp ;
|
||||
|
52
test/mp_back.cpp
Normal file
52
test/mp_back.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
|
||||
// Copyright 2015, 2019 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/core/lightweight_test_trait.hpp>
|
||||
#include <boost/mp11/algorithm.hpp>
|
||||
#include <boost/mp11/list.hpp>
|
||||
#include <boost/mp11/utility.hpp>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp11::mp_list;
|
||||
using boost::mp11::mp_back;
|
||||
|
||||
using L1 = mp_list<void>;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_back<L1>, void>));
|
||||
|
||||
using L2 = mp_list<float, void, int[]>;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_back<L2>, int[]>));
|
||||
|
||||
using L3 = std::tuple<int>;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_back<L3>, int>));
|
||||
|
||||
using L4 = std::pair<char, double>;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_back<L4>, double>));
|
||||
|
||||
using L5 = std::add_const<void()>;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_back<L5>, void()>));
|
||||
|
||||
using boost::mp11::mp_iota_c;
|
||||
using boost::mp11::mp_size_t;
|
||||
|
||||
int const N = 137;
|
||||
|
||||
using L6 = mp_iota_c<N>;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_back<L6>, mp_size_t<N-1>>));
|
||||
|
||||
using boost::mp11::mp_valid;
|
||||
|
||||
using L7 = mp_list<>;
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_back, L7>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
49
test/mp_pop_back.cpp
Normal file
49
test/mp_pop_back.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
// Copyright 2015, 2019 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/core/lightweight_test_trait.hpp>
|
||||
#include <boost/mp11/algorithm.hpp>
|
||||
#include <boost/mp11/list.hpp>
|
||||
#include <boost/mp11/utility.hpp>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp11::mp_list;
|
||||
using boost::mp11::mp_pop_back;
|
||||
|
||||
using L1 = mp_list<void>;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_pop_back<L1>, mp_list<>>));
|
||||
|
||||
using L2 = mp_list<float, void, int[]>;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_pop_back<L2>, mp_list<float, void>>));
|
||||
|
||||
using L3 = std::tuple<int>;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_pop_back<L3>, std::tuple<>>));
|
||||
|
||||
using L4 = std::tuple<char, double>;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_pop_back<L4>, std::tuple<char>>));
|
||||
|
||||
using boost::mp11::mp_iota_c;
|
||||
using boost::mp11::mp_size_t;
|
||||
|
||||
int const N = 137;
|
||||
|
||||
using L6 = mp_iota_c<N>;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_pop_back<L6>, mp_iota_c<N-1>>));
|
||||
|
||||
using boost::mp11::mp_valid;
|
||||
|
||||
using L7 = mp_list<>;
|
||||
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_pop_back, L7>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user