1
0
forked from boostorg/mp11

Merge branch 'develop'

This commit is contained in:
Peter Dimov
2015-06-22 00:50:49 +03:00
15 changed files with 602 additions and 201 deletions

View File

@@ -9,6 +9,7 @@
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/mp11/list.hpp>
#include <boost/mp11/algorithm.hpp>
#include <boost/mp11/integral.hpp>
#include <boost/mp11/utility.hpp>

View File

@@ -0,0 +1,248 @@
#ifndef BOOST_MP11_ALGORITHM_HPP_INCLUDED
#define BOOST_MP11_ALGORITHM_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/list.hpp>
#include <boost/mp11/integral.hpp>
#include <boost/mp11/detail/mp_plus.hpp>
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <type_traits>
namespace boost
{
// mp_assign<L1, L2>
namespace detail
{
template<class L1, class L2> struct mp_assign_impl;
template<template<class...> class L1, class... T, template<class...> class L2, class... U> struct mp_assign_impl<L1<T...>, L2<U...>>
{
using type = L1<U...>;
};
} // namespace detail
template<class L1, class L2> using mp_assign = typename detail::mp_assign_impl<L1, L2>::type;
// mp_clear<L>
template<class L> using mp_clear = mp_assign<L, mp_list<>>;
// mp_transform<F, L...>
namespace detail
{
template<template<class...> class F, class... L> struct mp_transform_impl;
template<template<class...> class F, class... L> using mp_transform = typename mp_transform_impl<F, L...>::type;
template<template<class...> class F, template<class...> class L, class... T> struct mp_transform_impl<F, L<T...>>
{
using type = L<F<T>...>;
};
template<template<class...> class F, template<class...> class L1, class... T1, template<class...> class L2, class... T2> struct mp_transform_impl<F, L1<T1...>, L2<T2...>>
{
static_assert( sizeof...(T1) == sizeof...(T2), "The arguments of mp_transform should be of the same size" );
using type = L1<F<T1,T2>...>;
};
template<template<class...> class F, template<class...> class L1, class... T1, template<class...> class L2, class... T2, template<class...> class L3, class... T3> struct mp_transform_impl<F, L1<T1...>, L2<T2...>, L3<T3...>>
{
static_assert( sizeof...(T1) == sizeof...(T2) && sizeof...(T1) == sizeof...(T3), "The arguments of mp_transform should be of the same size" );
using type = L1<F<T1,T2,T3>...>;
};
} // namespace detail
template<template<class...> class F, class... L> using mp_transform = typename detail::mp_transform_impl<F, L...>::type;
// mp_fill<L, V>
namespace detail
{
template<class L, class V> struct mp_fill_impl;
template<template<class...> class L, class... T, class V> struct mp_fill_impl<L<T...>, V>
{
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 )
template<class...> struct _f { using type = V; };
using type = L<typename _f<T>::type...>;
#else
template<class...> using _f = V;
using type = L<_f<T>...>;
#endif
};
} // namespace detail
template<class L, class V> using mp_fill = typename detail::mp_fill_impl<L, V>::type;
// mp_count<L, V>
namespace detail
{
template<class L, class V> struct mp_count_impl;
#if !defined( BOOST_NO_CXX11_CONSTEXPR )
constexpr std::size_t cx_plus()
{
return 0;
}
template<class T1, class... T> constexpr std::size_t cx_plus(T1 t1, T... t)
{
return t1 + cx_plus(t...);
}
template<template<class...> class L, class... T, class V> struct mp_count_impl<L<T...>, V>
{
using type = mp_size_t<cx_plus(std::is_same<T, V>::value...)>;
};
#else
template<template<class...> class L, class... T, class V> struct mp_count_impl<L<T...>, V>
{
using type = mp_size_t<mp_plus<std::is_same<T, V>...>::value>;
};
#endif
} // namespace detail
template<class L, class V> using mp_count = typename detail::mp_count_impl<L, V>::type;
// mp_count_if<L, P>
namespace detail
{
template<class L, template<class...> class P> struct mp_count_if_impl;
#if !defined( BOOST_NO_CXX11_CONSTEXPR )
template<template<class...> class L, class... T, template<class...> class P> struct mp_count_if_impl<L<T...>, P>
{
using type = mp_size_t<cx_plus(mp_to_bool<P<T>>::value...)>;
};
#else
template<template<class...> class L, class... T, template<class...> class P> struct mp_count_if_impl<L<T...>, P>
{
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 )
template<class T> struct _f { using type = mp_to_bool<P<T>>; };
using type = mp_size_t<mp_plus<typename _f<T>::type...>::value>;
#else
using type = mp_size_t<mp_plus<mp_to_bool<P<T>>...>::value>;
#endif
};
#endif
} // namespace detail
template<class L, template<class...> class P> using mp_count_if = typename detail::mp_count_if_impl<L, P>::type;
// mp_contains<L, V>
template<class L, class V> using mp_contains = mp_to_bool<mp_count<L, V>>;
// mp_repeat(_c)<L, N>
namespace detail
{
template<class L, std::size_t N> struct mp_repeat_c_impl
{
using _l1 = typename mp_repeat_c_impl<L, N/2>::type;
using _l2 = typename mp_repeat_c_impl<L, N%2>::type;
using type = mp_append<_l1, _l1, _l2>;
};
template<class L> struct mp_repeat_c_impl<L, 0>
{
using type = mp_clear<L>;
};
template<class L> struct mp_repeat_c_impl<L, 1>
{
using type = L;
};
template<class L, class N> struct mp_repeat_impl
{
static_assert( N::value >= 0, "mp_repeat<L, N>: N must not be negative" );
using type = typename mp_repeat_c_impl<L, N::value>::type;
};
} // namespace detail
template<class L, std::size_t N> using mp_repeat_c = typename detail::mp_repeat_c_impl<L, N>::type;
template<class L, class N> using mp_repeat = typename detail::mp_repeat_impl<L, N>::type;
// mp_product<F, L...>
namespace detail
{
template<template<class...> class F, class P, class... L> struct mp_product_impl_2;
template<template<class...> class F, class P> struct mp_product_impl_2<F, P>
{
using type = mp_list<mp_rename<P, F>>;
};
template<template<class...> class F, class P, template<class...> class L1, class... T1, class... L> struct mp_product_impl_2<F, P, L1<T1...>, L...>
{
using type = mp_append<typename mp_product_impl_2<F, mp_push_back<P, T1>, L...>::type...>;
};
template<template<class...> class F, class... L> struct mp_product_impl;
template<template<class...> class F, class L1, class... L> struct mp_product_impl<F, L1, L...>
{
using type = mp_assign<L1, typename mp_product_impl_2<F, mp_list<>, L1, L...>::type>;
};
} // namespace detail
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>
// mp_at(_c)<L, I>
// mp_find<L, V>
// mp_find_if<L, P>
// mp_find_index<L, V>
// mp_find_index_if<L, P>
// mp_reverse<L>
// mp_copy_if<L, P>
// 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>
} // namespace boost
#endif // #ifndef BOOST_MP11_ALGORITHM_HPP_INCLUDED

View File

@@ -20,45 +20,23 @@ namespace detail
template<class... T> struct mp_plus_impl;
#if defined( BOOST_NO_CXX11_CONSTEXPR )
template<> struct mp_plus_impl<>
{
using type = std::integral_constant<int, 0>;
using type = std::integral_constant<int, 0>;
};
template<class T1, class... T> struct mp_plus_impl<T1, T...>
{
static const/*expr*/ auto _v = T1::value + mp_plus<T...>::value;
using type = std::integral_constant< typename std::remove_const<decltype(_v)>::type, _v >;
static const/*expr*/ auto _v = T1::value + mp_plus_impl<T...>::type::value;
using type = std::integral_constant<typename std::remove_const<decltype(_v)>::type, _v>;
};
template<class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class... T> struct mp_plus_impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T...>
{
static const/*expr*/ auto _v = T1::value + T2::value + T3::value + T4::value + T5::value + T6::value + T7::value + T8::value + T9::value + T10::value + mp_plus<T...>::value;
using type = std::integral_constant< typename std::remove_const<decltype(_v)>::type, _v >;
static const/*expr*/ auto _v = T1::value + T2::value + T3::value + T4::value + T5::value + T6::value + T7::value + T8::value + T9::value + T10::value + mp_plus_impl<T...>::type::value;
using type = std::integral_constant<typename std::remove_const<decltype(_v)>::type, _v>;
};
#else
constexpr int cx_plus()
{
return 0;
}
template<class T1, class... T> constexpr auto cx_plus( T1 t1, T... t ) -> decltype( t1 + cx_plus( t... ) )
{
return t1 + cx_plus( t... );
}
template<class... T> struct mp_plus_impl
{
static constexpr auto _v = cx_plus( T::value... );
using type = std::integral_constant< typename std::remove_const<decltype(_v)>::type, _v >;
};
#endif
} // namespace detail
template<class... T> using mp_plus = typename detail::mp_plus_impl<T...>::type;

View File

@@ -9,10 +9,6 @@
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/mp11/integral.hpp>
#include <boost/mp11/detail/mp_plus.hpp>
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <type_traits>
namespace boost
{
@@ -176,171 +172,6 @@ template<template<class...> class L1, class... T1, template<class...> class L2,
template<class... L> using mp_append = typename detail::mp_append_impl<L...>::type;
// mp_assign<L1, L2>
namespace detail
{
template<class L1, class L2> struct mp_assign_impl;
template<template<class...> class L1, class... T, template<class...> class L2, class... U> struct mp_assign_impl<L1<T...>, L2<U...>>
{
using type = L1<U...>;
};
} // namespace detail
template<class L1, class L2> using mp_assign = typename detail::mp_assign_impl<L1, L2>::type;
// mp_clear<L>
template<class L> using mp_clear = mp_assign<L, mp_list<>>;
// mp_transform<F, L...>
namespace detail
{
template<template<class...> class F, class... L> struct mp_transform_impl;
template<template<class...> class F, class... L> using mp_transform = typename mp_transform_impl<F, L...>::type;
template<template<class...> class F, template<class...> class L, class... T> struct mp_transform_impl<F, L<T...>>
{
using type = L<F<T>...>;
};
template<template<class...> class F, template<class...> class L1, class... T1, template<class...> class L2, class... T2> struct mp_transform_impl<F, L1<T1...>, L2<T2...>>
{
static_assert( sizeof...(T1) == sizeof...(T2), "The arguments of mp_transform should be of the same size" );
using type = L1<F<T1,T2>...>;
};
template<template<class...> class F, template<class...> class L1, class... T1, template<class...> class L2, class... T2, template<class...> class L3, class... T3> struct mp_transform_impl<F, L1<T1...>, L2<T2...>, L3<T3...>>
{
static_assert( sizeof...(T1) == sizeof...(T2) && sizeof...(T1) == sizeof...(T3), "The arguments of mp_transform should be of the same size" );
using type = L1<F<T1,T2,T3>...>;
};
} // namespace detail
template<template<class...> class F, class... L> using mp_transform = typename detail::mp_transform_impl<F, L...>::type;
// mp_fill<L, V>
namespace detail
{
template<class L, class V> struct mp_fill_impl;
template<template<class...> class L, class... T, class V> struct mp_fill_impl<L<T...>, V>
{
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 )
template<class...> struct _f { using type = V; };
using type = L<typename _f<T>::type...>;
#else
template<class...> using _f = V;
using type = L<_f<T>...>;
#endif
};
} // namespace detail
template<class L, class V> using mp_fill = typename detail::mp_fill_impl<L, V>::type;
// mp_count<L, V>
namespace detail
{
template<class L, class V> struct mp_count_impl;
template<template<class...> class L, class... T, class V> struct mp_count_impl<L<T...>, V>
{
using type = mp_plus<std::is_same<T, V>...>;
};
} // namespace detail
template<class L, class V> using mp_count = typename detail::mp_count_impl<L, V>::type;
// mp_count_if<L, P>
namespace detail
{
template<class L, template<class...> class P> struct mp_count_if_impl;
template<template<class...> class L, class... T, template<class...> class P> struct mp_count_if_impl<L<T...>, P>
{
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 )
template<class T> struct _f { using type = mp_to_bool<P<T>>; };
using type = mp_plus<typename _f<T>::type...>;
#else
using type = mp_plus<mp_to_bool<P<T>>...>;
#endif
};
} // namespace detail
template<class L, template<class...> class P> using mp_count_if = typename detail::mp_count_if_impl<L, P>::type;
// mp_contains<L, V>
template<class L, class V> using mp_contains = mp_to_bool<mp_count<L, V>>;
// mp_repeat(_c)<L, N>
namespace detail
{
template<class L, std::size_t N> struct mp_repeat_c_impl
{
using _l1 = typename mp_repeat_c_impl<L, N/2>::type;
using _l2 = typename mp_repeat_c_impl<L, N%2>::type;
using type = mp_append<_l1, _l1, _l2>;
};
template<class L> struct mp_repeat_c_impl<L, 0>
{
using type = mp_clear<L>;
};
template<class L> struct mp_repeat_c_impl<L, 1>
{
using type = L;
};
template<class L, class N> struct mp_repeat_impl
{
static_assert( N::value >= 0, "mp_repeat<L, N>: N must not be negative" );
using type = typename mp_repeat_c_impl<L, N::value>::type;
};
} // namespace detail
template<class L, std::size_t N> using mp_repeat_c = typename detail::mp_repeat_c_impl<L, N>::type;
template<class L, class N> using mp_repeat = typename detail::mp_repeat_impl<L, N>::type;
// mp_drop<L, N>
// mp_take<L, N>
// mp_find<L, V>
// mp_find_if<L, P>
// mp_find_index<L, V>
// mp_find_index_if<L, P>
// mp_reverse<L>
// mp_copy_if<L, P>
// mp_remove_if<L, P>
// mp_product<L...>?
// 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>
} // namespace boost
#endif // #ifndef BOOST_MP11_LIST_HPP_INCLUDED

View File

@@ -11,6 +11,9 @@ import ../../config/checks/config : requires ;
REQ = ; #[ requires cxx11_variadic_templates cxx11_template_aliases cxx11_hdr_type_traits cxx11_hdr_tuple ] ;
# include-only
compile mp11.cpp : : : $(REQ) ;
# list
run mp_size.cpp : : : $(REQ) ;
run mp_empty.cpp : : : $(REQ) ;
@@ -24,12 +27,13 @@ run mp_rename.cpp : : : $(REQ) ;
run mp_append.cpp : : : $(REQ) ;
run mp_assign.cpp : : : $(REQ) ;
run mp_clear.cpp : : : $(REQ) ;
#run mp_transform.cpp : : : $(REQ) ;
run mp_transform.cpp : : : $(REQ) ;
run mp_fill.cpp : : : $(REQ) ;
#run mp_count.cpp : : : $(REQ) ;
#run mp_count_if.cpp : : : $(REQ) ;
#run mp_contains.cpp : : : $(REQ) ;
run mp_count.cpp : : : $(REQ) ;
run mp_count_if.cpp : : : $(REQ) ;
run mp_contains.cpp : : : $(REQ) ;
run mp_repeat.cpp : : : $(REQ) ;
run mp_product.cpp : : : $(REQ) ;
# integral
run integral.cpp : : : $(REQ) ;

14
test/mp11.cpp Normal file
View File

@@ -0,0 +1,14 @@
// 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.hpp>
int main()
{
}

View File

@@ -8,6 +8,7 @@
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/mp11/algorithm.hpp>
#include <boost/mp11/list.hpp>
#include <type_traits>
#include <tuple>

View File

@@ -8,6 +8,7 @@
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/mp11/algorithm.hpp>
#include <boost/mp11/list.hpp>
#include <type_traits>
#include <tuple>

64
test/mp_contains.cpp Normal file
View File

@@ -0,0 +1,64 @@
// 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 {};
int main()
{
using boost::mp_list;
using boost::mp_contains;
using boost::mp_true;
using boost::mp_false;
{
using L1 = mp_list<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L1, void>, mp_false>));
using L2 = mp_list<X1, X2, X3, X2, X3, X3>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L2, void>, mp_false>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L2, X1>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L2, X2>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L2, X3>, mp_true>));
}
{
using L3 = std::tuple<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L3, void>, mp_false>));
using L4 = std::tuple<X1, X2, X3, X2, X3, X3>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L4, void>, mp_false>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L4, X1>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L4, X2>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L4, X3>, mp_true>));
}
{
using L5 = std::pair<X1, X2>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L5, void>, mp_false>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L5, X1>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_contains<L5, X2>, mp_true>));
}
return boost::report_errors();
}

63
test/mp_count.cpp Normal file
View File

@@ -0,0 +1,63 @@
// 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 {};
int main()
{
using boost::mp_list;
using boost::mp_count;
using boost::mp_size_t;
{
using L1 = mp_list<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L1, void>, mp_size_t<0>>));
using L2 = mp_list<X1, X2, X3, X2, X3, X3>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L2, void>, mp_size_t<0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L2, X1>, mp_size_t<1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L2, X2>, mp_size_t<2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L2, X3>, mp_size_t<3>>));
}
{
using L3 = std::tuple<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L3, void>, mp_size_t<0>>));
using L4 = std::tuple<X1, X2, X3, X2, X3, X3>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L4, void>, mp_size_t<0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L4, X1>, mp_size_t<1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L4, X2>, mp_size_t<2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L4, X3>, mp_size_t<3>>));
}
{
using L5 = std::pair<X1, X2>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L5, void>, mp_size_t<0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L5, X1>, mp_size_t<1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L5, X2>, mp_size_t<1>>));
}
return boost::report_errors();
}

59
test/mp_count_if.cpp Normal file
View File

@@ -0,0 +1,59 @@
// 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 {};
int main()
{
using boost::mp_list;
using boost::mp_count_if;
using boost::mp_size_t;
{
using L1 = mp_list<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count_if<L1, std::is_const>, mp_size_t<0>>));
using L2 = mp_list<X1, X1 const, X1*, X1 const, X1*, X1*>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count_if<L2, std::is_volatile>, mp_size_t<0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count_if<L2, std::is_const>, mp_size_t<2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count_if<L2, std::is_pointer>, mp_size_t<3>>));
}
{
using L1 = std::tuple<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count_if<L1, std::is_const>, mp_size_t<0>>));
using L2 = std::tuple<X1, X1 const, X1*, X1 const, X1*, X1*>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count_if<L2, std::is_volatile>, mp_size_t<0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count_if<L2, std::is_const>, mp_size_t<2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count_if<L2, std::is_pointer>, mp_size_t<3>>));
}
{
using L2 = std::pair<X1 const, X1*>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count_if<L2, std::is_volatile>, mp_size_t<0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count_if<L2, std::is_const>, mp_size_t<1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count_if<L2, std::is_pointer>, mp_size_t<1>>));
}
return boost::report_errors();
}

View File

@@ -8,6 +8,7 @@
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/mp11/algorithm.hpp>
#include <boost/mp11/list.hpp>
#include <type_traits>
#include <tuple>

50
test/mp_product.cpp Normal file
View File

@@ -0,0 +1,50 @@
// 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 {};
struct Y1 {};
struct Z1 {};
struct Z2 {};
template<class T1, class T2, class T3> struct F {};
int main()
{
using boost::mp_list;
using boost::mp_product;
{
using L1 = std::tuple<X1, X2, X3>;
using L2 = mp_list<Y1>;
using L3 = std::pair<Z1, Z2>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_product<F, L1, L2, L3>, std::tuple<F<X1, Y1, Z1>, F<X1, Y1, Z2>, F<X2, Y1, Z1>, F<X2, Y1, Z2>, F<X3, Y1, Z1>, F<X3, Y1, Z2>>>));
}
{
using L1 = std::tuple<X1, X2, X3>;
using L2 = mp_list<>;
using L3 = std::pair<Z1, Z2>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_product<F, L1, L2, L3>, std::tuple<>>));
}
return boost::report_errors();
}

View File

@@ -7,9 +7,10 @@
// 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/integral.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <type_traits>
#include <tuple>
#include <utility>

85
test/mp_transform.cpp Normal file
View 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/core/lightweight_test_trait.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
struct X1 {};
struct X2 {};
struct X3 {};
struct X4 {};
struct Y1 {};
struct Y2 {};
struct Y3 {};
struct Y4 {};
struct Z1 {};
struct Z2 {};
struct Z3 {};
struct Z4 {};
template<class T> using add_pointer = typename std::add_pointer<T>::type;
template<class T, class U> using is_same = typename std::is_same<T, U>::type;
int main()
{
using boost::mp_list;
using boost::mp_transform;
using L1 = mp_list<X1, X2, X3, X4>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<mp_list, L1>, mp_list<mp_list<X1>, mp_list<X2>, mp_list<X3>, mp_list<X4>>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<std::tuple, L1>, mp_list<std::tuple<X1>, std::tuple<X2>, std::tuple<X3>, std::tuple<X4>>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<std::add_pointer, L1>, mp_list<std::add_pointer<X1>, std::add_pointer<X2>, std::add_pointer<X3>, std::add_pointer<X4>>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<add_pointer, L1>, mp_list<X1*, X2*, X3*, X4*>>));
using L2 = std::tuple<Y1, Y2, Y3, Y4>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<mp_list, L1, L2>, mp_list<mp_list<X1, Y1>, mp_list<X2, Y2>, mp_list<X3, Y3>, mp_list<X4, Y4>>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<std::tuple, L1, L2>, mp_list<std::tuple<X1, Y1>, std::tuple<X2, Y2>, std::tuple<X3, Y3>, std::tuple<X4, Y4>>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<std::pair, L1, L2>, mp_list<std::pair<X1, Y1>, std::pair<X2, Y2>, std::pair<X3, Y3>, std::pair<X4, Y4>>>));
using L3 = mp_list<Z1, Z2, Z3, Z4>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<mp_list, L1, L2, L3>, mp_list<mp_list<X1, Y1, Z1>, mp_list<X2, Y2, Z2>, mp_list<X3, Y3, Z3>, mp_list<X4, Y4, Z4>>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<std::tuple, L1, L2, L3>, mp_list<std::tuple<X1, Y1, Z1>, std::tuple<X2, Y2, Z2>, std::tuple<X3, Y3, Z3>, std::tuple<X4, Y4, Z4>>>));
//
using L4 = std::tuple<X1, Y2, X3, Y4>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<is_same, L1, L1>, mp_list<std::true_type, std::true_type, std::true_type, std::true_type>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<is_same, L1, L2>, mp_list<std::false_type, std::false_type, std::false_type, std::false_type>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<is_same, L1, L4>, mp_list<std::true_type, std::false_type, std::true_type, std::false_type>>));
//
using L5 = std::pair<X1, X2>;
using L6 = std::pair<Y1, Y2>;
using L7 = std::pair<X1, Y2>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<mp_list, L5>, std::pair<mp_list<X1>, mp_list<X2>>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<mp_list, L5, L6>, std::pair<mp_list<X1, Y1>, mp_list<X2, Y2>>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<mp_list, L5, L6, L7>, std::pair<mp_list<X1, Y1, X1>, mp_list<X2, Y2, Y2>>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<add_pointer, L5>, std::pair<X1*, X2*>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<is_same, L5, L5>, std::pair<std::true_type, std::true_type>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<is_same, L5, L6>, std::pair<std::false_type, std::false_type>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform<is_same, L5, L7>, std::pair<std::true_type, std::false_type>>));
//
return boost::report_errors();
}