1
0
forked from boostorg/mp11

Add tests for mp_count, mp_count_if.

This commit is contained in:
Peter Dimov
2015-06-22 00:06:50 +03:00
parent 894f6cf129
commit 138e4de0a8
5 changed files with 164 additions and 32 deletions

View File

@@ -96,11 +96,32 @@ 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_plus<std::is_same<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;
@@ -111,20 +132,31 @@ 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_plus<typename _f<T>::type...>;
using type = mp_size_t<mp_plus<typename _f<T>::type...>::value>;
#else
using type = mp_plus<mp_to_bool<P<T>>...>;
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;