]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/mp11/detail/mp_count.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / mp11 / detail / mp_count.hpp
CommitLineData
b32b8144
FG
1#ifndef BOOST_MP11_DETAIL_MP_COUNT_HPP_INCLUDED
2#define BOOST_MP11_DETAIL_MP_COUNT_HPP_INCLUDED
3
4// Copyright 2015, 2016 Peter Dimov.
5//
6// Distributed under the Boost Software License, Version 1.0.
7//
8// See accompanying file LICENSE_1_0.txt or copy at
9// http://www.boost.org/LICENSE_1_0.txt
10
11#include <boost/mp11/integral.hpp>
12#include <boost/mp11/detail/mp_plus.hpp>
13#include <boost/mp11/detail/config.hpp>
b32b8144
FG
14
15namespace boost
16{
17namespace mp11
18{
19
20// mp_count<L, V>
21namespace detail
22{
23
24template<class L, class V> struct mp_count_impl;
25
26#if defined( BOOST_MP11_HAS_FOLD_EXPRESSIONS )
27
28template<template<class...> class L, class... T, class V> struct mp_count_impl<L<T...>, V>
29{
30 using type = mp_size_t<(std::is_same<T, V>::value + ... + 0)>;
31};
32
33#elif !defined( BOOST_MP11_NO_CONSTEXPR )
34
35constexpr std::size_t cx_plus()
36{
37 return 0;
38}
39
40template<class T1, class... T> constexpr std::size_t cx_plus(T1 t1, T... t)
41{
92f5a8d4 42 return static_cast<std::size_t>(t1) + cx_plus(t...);
b32b8144
FG
43}
44
45template<class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class... T>
46constexpr std::size_t cx_plus(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T... t)
47{
92f5a8d4 48 return static_cast<std::size_t>(t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10) + cx_plus(t...);
b32b8144
FG
49}
50
51template<template<class...> class L, class... T, class V> struct mp_count_impl<L<T...>, V>
52{
53 using type = mp_size_t<cx_plus(std::is_same<T, V>::value...)>;
54};
55
56#else
57
58template<template<class...> class L, class... T, class V> struct mp_count_impl<L<T...>, V>
59{
60 using type = mp_size_t<mp_plus<std::is_same<T, V>...>::value>;
61};
62
63#endif
64
65} // namespace detail
66
67template<class L, class V> using mp_count = typename detail::mp_count_impl<L, V>::type;
68
69// mp_count_if<L, P>
70namespace detail
71{
72
73template<class L, template<class...> class P> struct mp_count_if_impl;
74
92f5a8d4 75#if defined( BOOST_MP11_HAS_FOLD_EXPRESSIONS ) && !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1920 )
b32b8144
FG
76
77template<template<class...> class L, class... T, template<class...> class P> struct mp_count_if_impl<L<T...>, P>
78{
79 using type = mp_size_t<(mp_to_bool<P<T>>::value + ... + 0)>;
80};
81
82#elif !defined( BOOST_MP11_NO_CONSTEXPR )
83
84template<template<class...> class L, class... T, template<class...> class P> struct mp_count_if_impl<L<T...>, P>
85{
86 using type = mp_size_t<cx_plus(mp_to_bool<P<T>>::value...)>;
87};
88
89#else
90
91template<template<class...> class L, class... T, template<class...> class P> struct mp_count_if_impl<L<T...>, P>
92{
92f5a8d4 93#if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1920 )
b32b8144
FG
94
95 template<class T> struct _f { using type = mp_to_bool<P<T>>; };
96 using type = mp_size_t<mp_plus<typename _f<T>::type...>::value>;
97
98#else
99
100 using type = mp_size_t<mp_plus<mp_to_bool<P<T>>...>::value>;
101
102#endif
103};
104
105#endif
106
107} // namespace detail
108
109template<class L, template<class...> class P> using mp_count_if = typename detail::mp_count_if_impl<L, P>::type;
110template<class L, class Q> using mp_count_if_q = mp_count_if<L, Q::template fn>;
111
112} // namespace mp11
113} // namespace boost
114
115#endif // #ifndef BOOST_MP11_DETAIL_MP_COUNT_HPP_INCLUDED