]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/pfr/detail/size_array.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / pfr / detail / size_array.hpp
1 // Copyright (c) 2016-2022 Antony Polukhin
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #ifndef BOOST_PFR_DETAIL_SIZE_ARRAY_HPP
7 #define BOOST_PFR_DETAIL_SIZE_ARRAY_HPP
8 #pragma once
9
10 #include <boost/pfr/detail/config.hpp>
11
12 #include <cstddef> // metaprogramming stuff
13
14 namespace boost { namespace pfr { namespace detail {
15
16 ///////////////////// Array that has the constexpr
17 template <std::size_t N>
18 struct size_array { // libc++ misses constexpr on operator[]
19 typedef std::size_t type;
20 std::size_t data[N];
21
22 static constexpr std::size_t size() noexcept { return N; }
23
24 constexpr std::size_t count_nonzeros() const noexcept {
25 std::size_t count = 0;
26 for (std::size_t i = 0; i < size(); ++i) {
27 if (data[i]) {
28 ++ count;
29 }
30 }
31 return count;
32 }
33
34 constexpr std::size_t count_from_opening_till_matching_parenthis_seq(std::size_t from, std::size_t opening_parenthis, std::size_t closing_parenthis) const noexcept {
35 if (data[from] != opening_parenthis) {
36 return 0;
37 }
38 std::size_t unclosed_parnthesis = 0;
39 std::size_t count = 0;
40 for (; ; ++from) {
41 if (data[from] == opening_parenthis) {
42 ++ unclosed_parnthesis;
43 } else if (data[from] == closing_parenthis) {
44 -- unclosed_parnthesis;
45 }
46 ++ count;
47
48 if (unclosed_parnthesis == 0) {
49 return count;
50 }
51 }
52
53 return count;
54 }
55 };
56
57 template <>
58 struct size_array<0> { // libc++ misses constexpr on operator[]
59 typedef std::size_t type;
60 std::size_t data[1];
61
62 static constexpr std::size_t size() noexcept { return 0; }
63
64 constexpr std::size_t count_nonzeros() const noexcept {
65 return 0;
66 }
67 };
68
69 template <std::size_t I, std::size_t N>
70 constexpr std::size_t get(const size_array<N>& a) noexcept {
71 static_assert(I < N, "====================> Boost.PFR: Array index out of bounds");
72 return a.data[I];
73 }
74
75
76
77 }}} // namespace boost::pfr::detail
78
79 #endif // BOOST_PFR_DETAIL_SIZE_ARRAY_HPP