]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/mp11/detail/mp_count.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / mp11 / detail / mp_count.hpp
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>
14 #include <boost/config.hpp>
15
16 namespace boost
17 {
18 namespace mp11
19 {
20
21 // mp_count<L, V>
22 namespace detail
23 {
24
25 template<class L, class V> struct mp_count_impl;
26
27 #if defined( BOOST_MP11_HAS_FOLD_EXPRESSIONS )
28
29 template<template<class...> class L, class... T, class V> struct mp_count_impl<L<T...>, V>
30 {
31 using type = mp_size_t<(std::is_same<T, V>::value + ... + 0)>;
32 };
33
34 #elif !defined( BOOST_MP11_NO_CONSTEXPR )
35
36 constexpr std::size_t cx_plus()
37 {
38 return 0;
39 }
40
41 template<class T1, class... T> constexpr std::size_t cx_plus(T1 t1, T... t)
42 {
43 return t1 + cx_plus(t...);
44 }
45
46 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class... T>
47 constexpr 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)
48 {
49 return t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10 + cx_plus(t...);
50 }
51
52 template<template<class...> class L, class... T, class V> struct mp_count_impl<L<T...>, V>
53 {
54 using type = mp_size_t<cx_plus(std::is_same<T, V>::value...)>;
55 };
56
57 #else
58
59 template<template<class...> class L, class... T, class V> struct mp_count_impl<L<T...>, V>
60 {
61 using type = mp_size_t<mp_plus<std::is_same<T, V>...>::value>;
62 };
63
64 #endif
65
66 } // namespace detail
67
68 template<class L, class V> using mp_count = typename detail::mp_count_impl<L, V>::type;
69
70 // mp_count_if<L, P>
71 namespace detail
72 {
73
74 template<class L, template<class...> class P> struct mp_count_if_impl;
75
76 #if defined( BOOST_MP11_HAS_FOLD_EXPRESSIONS )
77
78 template<template<class...> class L, class... T, template<class...> class P> struct mp_count_if_impl<L<T...>, P>
79 {
80 using type = mp_size_t<(mp_to_bool<P<T>>::value + ... + 0)>;
81 };
82
83 #elif !defined( BOOST_MP11_NO_CONSTEXPR )
84
85 template<template<class...> class L, class... T, template<class...> class P> struct mp_count_if_impl<L<T...>, P>
86 {
87 using type = mp_size_t<cx_plus(mp_to_bool<P<T>>::value...)>;
88 };
89
90 #else
91
92 template<template<class...> class L, class... T, template<class...> class P> struct mp_count_if_impl<L<T...>, P>
93 {
94 #if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, < 1920 )
95
96 template<class T> struct _f { using type = mp_to_bool<P<T>>; };
97 using type = mp_size_t<mp_plus<typename _f<T>::type...>::value>;
98
99 #else
100
101 using type = mp_size_t<mp_plus<mp_to_bool<P<T>>...>::value>;
102
103 #endif
104 };
105
106 #endif
107
108 } // namespace detail
109
110 template<class L, template<class...> class P> using mp_count_if = typename detail::mp_count_if_impl<L, P>::type;
111 template<class L, class Q> using mp_count_if_q = mp_count_if<L, Q::template fn>;
112
113 } // namespace mp11
114 } // namespace boost
115
116 #endif // #ifndef BOOST_MP11_DETAIL_MP_COUNT_HPP_INCLUDED