forked from boostorg/mp11
Add mp_transform_if, mp_map_update
This commit is contained in:
1 parent
c054b2b2fe
commit
6fb4cee7b2
6 files changed
+143
-3
No files matched your search
@@ -30,6 +30,7 @@ run mp_append.cpp : : : $(REQ) ;
|
||||
run mp_assign.cpp : : : $(REQ) ;
|
||||
run mp_clear.cpp : : : $(REQ) ;
|
||||
run mp_transform.cpp : : : $(REQ) ;
|
||||
run mp_transform_if.cpp : : : $(REQ) ;
|
||||
run mp_fill.cpp : : : $(REQ) ;
|
||||
run mp_count.cpp : : : $(REQ) ;
|
||||
run mp_count_if.cpp : : : $(REQ) ;
|
||||
@@ -95,3 +96,4 @@ run mp_map_contains.cpp : : : $(REQ) ;
|
||||
run mp_map_insert.cpp : : : $(REQ) ;
|
||||
run mp_map_replace.cpp : : : $(REQ) ;
|
||||
run mp_map_erase.cpp : : : $(REQ) ;
|
||||
run mp_map_update.cpp : : : $(REQ) ;
|
||||
@@ -18,7 +18,6 @@ int main()
|
||||
{
|
||||
using boost::mp_map_erase;
|
||||
using boost::mp_list;
|
||||
using boost::mp_push_back;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<mp_list<>, void>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<std::tuple<>, int>, std::tuple<>>));
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
// Copyright 2016, 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/map.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>
|
||||
|
||||
using boost::mp_int;
|
||||
|
||||
template<class T> using inc = mp_int<T::value + 1>;
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp_map_update;
|
||||
using boost::mp_list;
|
||||
|
||||
using M1 = mp_list<>;
|
||||
|
||||
using M2 = mp_map_update< M1, std::pair<char, mp_int<0>>, inc >;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<M2, mp_list<std::pair<char, mp_int<0>>>>));
|
||||
|
||||
using M3 = mp_map_update< M2, std::pair<char, mp_int<0>>, inc >;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<M3, mp_list<std::pair<char, mp_int<1>>>>));
|
||||
|
||||
using M4 = mp_map_update< M3, std::pair<int, mp_int<0>>, inc >;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<M4, mp_list<std::pair<char, mp_int<1>>, std::pair<int, mp_int<0>>>>));
|
||||
|
||||
using M5 = mp_map_update< M4, std::pair<long, mp_int<0>>, inc >;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<M5, mp_list<std::pair<char, mp_int<1>>, std::pair<int, mp_int<0>>, std::pair<long, mp_int<0>>>>));
|
||||
|
||||
using M6 = mp_map_update< M5, std::pair<long, mp_int<0>>, inc >;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<M6, mp_list<std::pair<char, mp_int<1>>, std::pair<int, mp_int<0>>, std::pair<long, mp_int<1>>>>));
|
||||
|
||||
using M7 = mp_map_update< M6, std::pair<char, mp_int<0>>, inc >;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<M7, mp_list<std::pair<char, mp_int<2>>, std::pair<int, mp_int<0>>, std::pair<long, mp_int<1>>>>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
|
||||
// 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 {};
|
||||
|
||||
template<class T> using add_pointer = T*;
|
||||
template<class T> using is_not_ref = boost::mp_not<std::is_reference<T>>;
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp_list;
|
||||
using boost::mp_transform_if;
|
||||
|
||||
using L1 = mp_list<X1, X2&, X3 const, X4 const&>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, add_pointer, L1>, mp_list<X1*, X2&, X3 const*, X4 const&>>));
|
||||
|
||||
using L2 = std::tuple<X1, X2&, X3 const, X4 const&>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, add_pointer, L2>, std::tuple<X1*, X2&, X3 const*, X4 const&>>));
|
||||
|
||||
using L3 = std::pair<X1 const, X2&>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, add_pointer, L3>, std::pair<X1 const*, X2&>>));
|
||||
|
||||
//
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in new issue
Block a user