forked from boostorg/mp11
Merge branch 'develop'
This commit is contained in:
@@ -49,6 +49,8 @@ template<class T, T N> struct make_integer_sequence_impl_
|
||||
{
|
||||
private:
|
||||
|
||||
static_assert( N >= 0, "make_integer_sequence<T, N>: N must not be negative" );
|
||||
|
||||
static T const M = N / 2;
|
||||
static T const R = N % 2;
|
||||
|
||||
|
@@ -10,7 +10,10 @@
|
||||
|
||||
#include <boost/mp11/list.hpp>
|
||||
#include <boost/mp11/integral.hpp>
|
||||
#include <boost/mp11/utility.hpp>
|
||||
#include <boost/mp11/detail/mp_plus.hpp>
|
||||
#include <boost/mp11/detail/mp_map_find.hpp>
|
||||
#include <boost/integer_sequence.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <type_traits>
|
||||
@@ -199,7 +202,6 @@ template<class L, std::size_t N> using mp_repeat_c = typename detail::mp_repeat_
|
||||
template<class L, class N> using mp_repeat = typename detail::mp_repeat_impl<L, N>::type;
|
||||
|
||||
// mp_product<F, L...>
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
@@ -227,8 +229,131 @@ template<template<class...> class F, class L1, class... L> struct mp_product_imp
|
||||
template<template<class...> class F, class... L> using mp_product = typename detail::mp_product_impl<F, L...>::type;
|
||||
|
||||
// mp_drop(_c)<L, N>
|
||||
// mp_take(_c)<L, N>
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class L, class L2> struct mp_drop_impl;
|
||||
|
||||
template<template<class...> class L, class... T, template<class...> class L2, class... U> struct mp_drop_impl<L<T...>, L2<U...>>
|
||||
{
|
||||
template<class... W> static mp_identity<L<W...>> f( U*..., mp_identity<W>*... );
|
||||
|
||||
using R = decltype( f( (mp_identity<T>*)0 ... ) );
|
||||
|
||||
using type = typename R::type;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class L, std::size_t N> using mp_drop_c = typename detail::mp_drop_impl<L, mp_repeat_c<mp_list<void>, N>>::type;
|
||||
|
||||
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>
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class S> struct mp_from_sequence_impl;
|
||||
|
||||
template<template<class T, T... I> class S, class U, U... J> struct mp_from_sequence_impl<S<U, J...>>
|
||||
{
|
||||
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>>;
|
||||
|
||||
// mp_at(_c)<L, I>
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class L, class I> struct mp_at_impl
|
||||
{
|
||||
static_assert( I::value >= 0, "mp_at<L, I>: I must not be negative" );
|
||||
|
||||
using _map = mp_transform<mp_list, mp_iota<mp_size<L>>, L>;
|
||||
|
||||
using type = mp_second<mp_map_find<_map, mp_size_t<I::value>>>;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class L, std::size_t I> using mp_at_c = typename detail::mp_at_impl<L, mp_size_t<I>>::type;
|
||||
|
||||
template<class L, class I> using mp_at = typename detail::mp_at_impl<L, I>::type;
|
||||
|
||||
// mp_take(_c)<L, N>
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class L, class N> struct mp_take_impl
|
||||
{
|
||||
static_assert( N::value >= 0, "mp_take<L, N>: N must not be negative" );
|
||||
|
||||
using _map = mp_transform<mp_list, mp_iota<mp_size<L>>, L>;
|
||||
|
||||
template<class I> using _f = mp_second<mp_map_find<_map, I>>;
|
||||
|
||||
using _ind = mp_iota_c<N::value>;
|
||||
|
||||
using type = mp_assign<L, mp_transform<_f, _ind>>;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class L, std::size_t N> using mp_take_c = typename detail::mp_take_impl<L, mp_size_t<N>>::type;
|
||||
|
||||
template<class L, class N> using mp_take = typename detail::mp_take_impl<L, N>::type;
|
||||
|
||||
// mp_replace<L, V, W>
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 )
|
||||
|
||||
template<class L, class V, class W> struct mp_replace_impl;
|
||||
|
||||
template<template<class...> class L, class... T, class V, class W> struct mp_replace_impl<L<T...>, V, W>
|
||||
{
|
||||
template<class A> struct _f { using type = mp_if<std::is_same<A, V>, W, A>; };
|
||||
|
||||
using type = L<typename _f<T>::type...>;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
template<class L, class V, class W> struct mp_replace_impl
|
||||
{
|
||||
template<class A> using _f = mp_if<std::is_same<A, V>, W, A>;
|
||||
|
||||
using type = mp_transform<_f, L>;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class L, class V, class W> using mp_replace = typename detail::mp_replace_impl<L, V, W>::type;
|
||||
|
||||
// mp_replace_if<L, P, W>
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class L, template<class...> class P, class W> struct mp_replace_if_impl
|
||||
{
|
||||
template<class T> using _f = mp_if<P<T>, W, T>;
|
||||
|
||||
using type = mp_transform<_f, L>;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class L, template<class...> class P, class W> using mp_replace_if = typename detail::mp_replace_if_impl<L, P, W>::type;
|
||||
|
||||
// mp_find<L, V>
|
||||
// mp_find_if<L, P>
|
||||
// mp_find_index<L, V>
|
||||
@@ -238,8 +363,6 @@ template<template<class...> class F, class... L> using mp_product = typename det
|
||||
// mp_remove_if<L, P>
|
||||
// mp_fold<L, V, F>
|
||||
// mp_reverse_fold<L, V, F>
|
||||
// mp_replace<L, V1, V2>?
|
||||
// mp_replace_if<L, P, V2>?
|
||||
// mp_partition<L, P>
|
||||
// mp_sort<L>
|
||||
|
||||
|
40
include/boost/mp11/detail/mp_map_find.hpp
Normal file
40
include/boost/mp11/detail/mp_map_find.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef BOOST_MP11_DETAIL_MP_MAP_FIND_HPP_INCLUDED
|
||||
#define BOOST_MP11_DETAIL_MP_MAP_FIND_HPP_INCLUDED
|
||||
|
||||
// Copyright 2015 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/utility.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
// mp_map_find
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class M, class K> struct mp_map_find_impl;
|
||||
|
||||
template<template<class...> class M, class... T, class K> struct mp_map_find_impl<M<T...>, K>
|
||||
{
|
||||
using U = mp_inherit<mp_identity<T>...>;
|
||||
|
||||
template<template<class...> class L, class... U> static mp_identity<L<K, U...>> f( mp_identity<L<K, U...>>* );
|
||||
static mp_identity<void> f( ... );
|
||||
|
||||
using V = decltype( f((U*)0) );
|
||||
|
||||
using type = typename V::type;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class M, class K> using mp_map_find = typename detail::mp_map_find_impl<M, K>::type;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_MP11_DETAIL_MP_MAP_FIND_HPP_INCLUDED
|
33
include/boost/tuple_for_each.hpp
Normal file
33
include/boost/tuple_for_each.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef BOOST_TUPLE_FOR_EACH_HPP_INCLUDED
|
||||
#define BOOST_TUPLE_FOR_EACH_HPP_INCLUDED
|
||||
|
||||
#include <boost/integer_sequence.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class Tp, std::size_t... J, class F> BOOST_CONSTEXPR F tuple_for_each_impl( Tp && tp, boost::integer_sequence<std::size_t, J...>, F && f )
|
||||
{
|
||||
using A = int[sizeof...(J)];
|
||||
return (void)A{ (f(std::get<J>(std::forward<Tp>(tp))), 0)... }, std::forward<F>(f);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class Tp, class F> BOOST_CONSTEXPR F tuple_for_each( Tp && tp, F && f )
|
||||
{
|
||||
using seq = boost::make_index_sequence<std::tuple_size<typename std::remove_reference<Tp>::type>::value>;
|
||||
return detail::tuple_for_each_impl( std::forward<Tp>(tp), seq(), std::forward<F>(f) );
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_TUPLE_FOR_EACH_HPP_INCLUDED
|
@@ -9,7 +9,7 @@
|
||||
import testing ;
|
||||
import ../../config/checks/config : requires ;
|
||||
|
||||
REQ = ; #[ requires cxx11_variadic_templates cxx11_template_aliases cxx11_hdr_type_traits cxx11_hdr_tuple ] ;
|
||||
REQ = ; #[ requires cxx11_variadic_templates cxx11_template_aliases cxx11_decltype cxx11_hdr_type_traits cxx11_hdr_tuple ] ;
|
||||
|
||||
# include-only
|
||||
compile mp11.cpp : : : $(REQ) ;
|
||||
@@ -34,6 +34,12 @@ run mp_count_if.cpp : : : $(REQ) ;
|
||||
run mp_contains.cpp : : : $(REQ) ;
|
||||
run mp_repeat.cpp : : : $(REQ) ;
|
||||
run mp_product.cpp : : : $(REQ) ;
|
||||
run mp_drop.cpp : : : $(REQ) ;
|
||||
run mp_iota.cpp : : : $(REQ) ;
|
||||
run mp_at.cpp : : : $(REQ) ;
|
||||
run mp_take.cpp : : : $(REQ) ;
|
||||
run mp_replace.cpp : : : $(REQ) ;
|
||||
run mp_replace_if.cpp : : : $(REQ) ;
|
||||
|
||||
# integral
|
||||
run integral.cpp : : : $(REQ) ;
|
||||
@@ -46,3 +52,7 @@ run mp_eval_if.cpp : : : $(REQ) ;
|
||||
|
||||
# integer_sequence
|
||||
run integer_sequence.cpp : : : $(REQ) ;
|
||||
|
||||
# tuple_for_each
|
||||
run tuple_for_each.cpp : : : $(REQ) ;
|
||||
run tuple_for_each_cx.cpp : : : $(REQ) ;
|
||||
|
74
test/mp_at.cpp
Normal file
74
test/mp_at.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
// Copyright 2015 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::mp_list;
|
||||
using boost::mp_at;
|
||||
using boost::mp_at_c;
|
||||
using boost::mp_size_t;
|
||||
|
||||
{
|
||||
using L1 = mp_list<X1, X2, X3, X4, X5>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at_c<L1, 0>, X1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at_c<L1, 1>, X2>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at_c<L1, 2>, X3>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at_c<L1, 3>, X4>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at_c<L1, 4>, X5>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at<L1, mp_size_t<0>>, X1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at<L1, mp_size_t<1>>, X2>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at<L1, mp_size_t<2>>, X3>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at<L1, mp_size_t<3>>, X4>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at<L1, mp_size_t<4>>, X5>));
|
||||
}
|
||||
|
||||
{
|
||||
using L1 = std::tuple<X1, X2, X3, X4, X5>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at_c<L1, 0>, X1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at_c<L1, 1>, X2>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at_c<L1, 2>, X3>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at_c<L1, 3>, X4>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at_c<L1, 4>, X5>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at<L1, mp_size_t<0>>, X1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at<L1, mp_size_t<1>>, X2>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at<L1, mp_size_t<2>>, X3>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at<L1, mp_size_t<3>>, X4>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at<L1, mp_size_t<4>>, X5>));
|
||||
}
|
||||
|
||||
{
|
||||
using L1 = std::pair<X1, X2>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at_c<L1, 0>, X1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at_c<L1, 1>, X2>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at<L1, mp_size_t<0>>, X1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_at<L1, mp_size_t<1>>, X2>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
85
test/mp_drop.cpp
Normal file
85
test/mp_drop.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
|
||||
// Copyright 2015 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::mp_list;
|
||||
using boost::mp_drop;
|
||||
using boost::mp_drop_c;
|
||||
using boost::mp_size_t;
|
||||
|
||||
{
|
||||
using L1 = mp_list<>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop_c<L1, 0>, L1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop<L1, mp_size_t<0>>, L1>));
|
||||
|
||||
using L2 = mp_list<X1, X2, X3, X4, X5>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop_c<L2, 0>, mp_list<X1, X2, X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop_c<L2, 1>, mp_list<X2, X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop_c<L2, 2>, mp_list<X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop_c<L2, 3>, mp_list<X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop_c<L2, 4>, mp_list<X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop_c<L2, 5>, mp_list<>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop<L2, mp_size_t<0>>, mp_list<X1, X2, X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop<L2, mp_size_t<1>>, mp_list<X2, X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop<L2, mp_size_t<2>>, mp_list<X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop<L2, mp_size_t<3>>, mp_list<X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop<L2, mp_size_t<4>>, mp_list<X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop<L2, mp_size_t<5>>, mp_list<>>));
|
||||
}
|
||||
|
||||
{
|
||||
using L1 = std::tuple<>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop_c<L1, 0>, L1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop<L1, mp_size_t<0>>, L1>));
|
||||
|
||||
using L2 = std::tuple<X1, X2, X3, X4, X5>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop_c<L2, 0>, std::tuple<X1, X2, X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop_c<L2, 1>, std::tuple<X2, X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop_c<L2, 2>, std::tuple<X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop_c<L2, 3>, std::tuple<X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop_c<L2, 4>, std::tuple<X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop_c<L2, 5>, std::tuple<>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop<L2, mp_size_t<0>>, std::tuple<X1, X2, X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop<L2, mp_size_t<1>>, std::tuple<X2, X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop<L2, mp_size_t<2>>, std::tuple<X3, X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop<L2, mp_size_t<3>>, std::tuple<X4, X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop<L2, mp_size_t<4>>, std::tuple<X5>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop<L2, mp_size_t<5>>, std::tuple<>>));
|
||||
}
|
||||
|
||||
{
|
||||
using L1 = std::pair<X1, X2>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop_c<L1, 0>, L1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_drop<L1, mp_size_t<0>>, L1>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
42
test/mp_iota.cpp
Normal file
42
test/mp_iota.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
// Copyright 2015 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/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp_list;
|
||||
using boost::mp_iota;
|
||||
using boost::mp_iota_c;
|
||||
using boost::mp_int;
|
||||
using boost::mp_size_t;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iota_c<0>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iota_c<1>, mp_list<mp_size_t<0>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iota_c<2>, mp_list<mp_size_t<0>, mp_size_t<1>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iota_c<3>, mp_list<mp_size_t<0>, mp_size_t<1>, mp_size_t<2>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iota_c<4>, mp_list<mp_size_t<0>, mp_size_t<1>, mp_size_t<2>, mp_size_t<3>>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iota<mp_size_t<0>>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iota<mp_size_t<1>>, mp_list<mp_size_t<0>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iota<mp_size_t<2>>, mp_list<mp_size_t<0>, mp_size_t<1>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iota<mp_size_t<3>>, mp_list<mp_size_t<0>, mp_size_t<1>, mp_size_t<2>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iota<mp_size_t<4>>, mp_list<mp_size_t<0>, mp_size_t<1>, mp_size_t<2>, mp_size_t<3>>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iota<mp_int<0>>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iota<mp_int<1>>, mp_list<mp_int<0>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iota<mp_int<2>>, mp_list<mp_int<0>, mp_int<1>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iota<mp_int<3>>, mp_list<mp_int<0>, mp_int<1>, mp_int<2>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iota<mp_int<4>>, mp_list<mp_int<0>, mp_int<1>, mp_int<2>, mp_int<3>>>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
61
test/mp_replace.cpp
Normal file
61
test/mp_replace.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
// Copyright 2015 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 {};
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp_list;
|
||||
using boost::mp_replace;
|
||||
|
||||
{
|
||||
using L1 = mp_list<>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L1, void, int[]>, L1>));
|
||||
|
||||
using L2 = mp_list<X1, X2, X3, X2, X3, X3>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, void, int[]>, L2>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, X1, int[]>, mp_list<int[], X2, X3, X2, X3, X3>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, X2, int[]>, mp_list<X1, int[], X3, int[], X3, X3>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, X3, int[]>, mp_list<X1, X2, int[], X2, int[], int[]>>));
|
||||
}
|
||||
|
||||
{
|
||||
using L1 = std::tuple<>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L1, void, int[]>, L1>));
|
||||
|
||||
using L2 = std::tuple<X1, X2, X3, X2, X3, X3>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, void, int[]>, L2>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, X1, int[]>, std::tuple<int[], X2, X3, X2, X3, X3>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, X2, int[]>, std::tuple<X1, int[], X3, int[], X3, X3>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, X3, int[]>, std::tuple<X1, X2, int[], X2, int[], int[]>>));
|
||||
}
|
||||
|
||||
{
|
||||
using L2 = std::pair<X1, X2>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, void, int[]>, L2>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, X1, int[]>, std::pair<int[], X2>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace<L2, X2, int[]>, std::pair<X1, int[]>>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
57
test/mp_replace_if.cpp
Normal file
57
test/mp_replace_if.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
// Copyright 2015 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 {};
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp_list;
|
||||
using boost::mp_replace_if;
|
||||
|
||||
{
|
||||
using L1 = mp_list<>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_if<L1, std::is_const, void>, L1>));
|
||||
|
||||
using L2 = mp_list<X1, X1 const, X1*, X1 const, X1*, X1*>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_if<L2, std::is_volatile, void>, L2>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_if<L2, std::is_const, void>, mp_list<X1, void, X1*, void, X1*, X1*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_if<L2, std::is_pointer, void>, mp_list<X1, X1 const, void, X1 const, void, void>>));
|
||||
}
|
||||
|
||||
{
|
||||
using L1 = std::tuple<>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_if<L1, std::is_const, void>, L1>));
|
||||
|
||||
using L2 = std::tuple<X1, X1 const, X1*, X1 const, X1*, X1*>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_if<L2, std::is_volatile, void>, L2>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_if<L2, std::is_const, void>, std::tuple<X1, void, X1*, void, X1*, X1*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_if<L2, std::is_pointer, void>, std::tuple<X1, X1 const, void, X1 const, void, void>>));
|
||||
}
|
||||
|
||||
{
|
||||
using L2 = std::pair<X1 const, X1*>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_if<L2, std::is_volatile, void>, L2>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_if<L2, std::is_const, void>, std::pair<void, X1*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_replace_if<L2, std::is_pointer, void>, std::pair<X1 const, void>>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
85
test/mp_take.cpp
Normal file
85
test/mp_take.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
|
||||
// Copyright 2015 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::mp_list;
|
||||
using boost::mp_take;
|
||||
using boost::mp_take_c;
|
||||
using boost::mp_size_t;
|
||||
|
||||
{
|
||||
using L1 = mp_list<>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L1, 0>, L1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L1, mp_size_t<0>>, L1>));
|
||||
|
||||
using L2 = mp_list<X1, X2, X3, X4, X5>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 0>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 1>, mp_list<X1>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 2>, mp_list<X1, X2>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 3>, mp_list<X1, X2, X3>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 4>, mp_list<X1, X2, X3, X4>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 5>, mp_list<X1, X2, X3, X4, X5>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<0>>, mp_list<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<1>>, mp_list<X1>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<2>>, mp_list<X1, X2>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<3>>, mp_list<X1, X2, X3>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<4>>, mp_list<X1, X2, X3, X4>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<5>>, mp_list<X1, X2, X3, X4, X5>>));
|
||||
}
|
||||
|
||||
{
|
||||
using L1 = std::tuple<>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L1, 0>, L1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L1, mp_size_t<0>>, L1>));
|
||||
|
||||
using L2 = std::tuple<X1, X2, X3, X4, X5>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 0>, std::tuple<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 1>, std::tuple<X1>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 2>, std::tuple<X1, X2>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 3>, std::tuple<X1, X2, X3>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 4>, std::tuple<X1, X2, X3, X4>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 5>, std::tuple<X1, X2, X3, X4, X5>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<0>>, std::tuple<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<1>>, std::tuple<X1>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<2>>, std::tuple<X1, X2>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<3>>, std::tuple<X1, X2, X3>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<4>>, std::tuple<X1, X2, X3, X4>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<5>>, std::tuple<X1, X2, X3, X4, X5>>));
|
||||
}
|
||||
|
||||
{
|
||||
using L1 = std::pair<X1, X2>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L1, 2>, L1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L1, mp_size_t<2>>, L1>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
90
test/tuple_for_each.cpp
Normal file
90
test/tuple_for_each.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
|
||||
// Copyright 2015 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/tuple_for_each.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <tuple>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <array>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::tuple<int, short, char> tp{ 1, 2, 3 };
|
||||
|
||||
{
|
||||
int s = 0;
|
||||
|
||||
boost::tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } );
|
||||
|
||||
BOOST_TEST_EQ( s, 123 );
|
||||
}
|
||||
|
||||
{
|
||||
int s = 0;
|
||||
|
||||
boost::tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } );
|
||||
|
||||
BOOST_TEST_EQ( s, 123 );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::tuple<std::unique_ptr<int>, std::unique_ptr<int>, std::unique_ptr<int>> tp{ std::unique_ptr<int>(new int(1)), std::unique_ptr<int>(new int(2)), std::unique_ptr<int>(new int(3)) };
|
||||
|
||||
int s = 0;
|
||||
|
||||
boost::tuple_for_each( std::move(tp), [&]( std::unique_ptr<int> p ){ s = s * 10 + *p; } );
|
||||
|
||||
BOOST_TEST_EQ( s, 123 );
|
||||
}
|
||||
|
||||
{
|
||||
std::pair<int, short> tp{ 1, 2 };
|
||||
|
||||
{
|
||||
int s = 0;
|
||||
|
||||
boost::tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } );
|
||||
|
||||
BOOST_TEST_EQ( s, 12 );
|
||||
}
|
||||
|
||||
{
|
||||
int s = 0;
|
||||
|
||||
boost::tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } );
|
||||
|
||||
BOOST_TEST_EQ( s, 12 );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::array<int, 3> tp{{ 1, 2, 3 }};
|
||||
|
||||
{
|
||||
int s = 0;
|
||||
|
||||
boost::tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } );
|
||||
|
||||
BOOST_TEST_EQ( s, 123 );
|
||||
}
|
||||
|
||||
{
|
||||
int s = 0;
|
||||
|
||||
boost::tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } );
|
||||
|
||||
BOOST_TEST_EQ( s, 123 );
|
||||
}
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
37
test/tuple_for_each_cx.cpp
Normal file
37
test/tuple_for_each_cx.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
// Copyright 2015 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/tuple_for_each.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if defined( BOOST_NO_CXX11_CONSTEXPR )
|
||||
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
|
||||
struct assert_is_integral
|
||||
{
|
||||
template<class T> constexpr bool operator()( T ) const
|
||||
{
|
||||
static_assert( std::is_integral<T>::value, "T must be an integral type" );
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
constexpr std::tuple<int, short, char> tp{ 1, 2, 3 };
|
||||
constexpr auto r = boost::tuple_for_each( tp, assert_is_integral() );
|
||||
(void)r;
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user