1 // Copyright (c) 2016-2022 Antony Polukhin
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)
6 #ifndef BOOST_PFR_DETAIL_SIZE_ARRAY_HPP
7 #define BOOST_PFR_DETAIL_SIZE_ARRAY_HPP
10 #include <boost/pfr/detail/config.hpp>
12 #include <cstddef> // metaprogramming stuff
14 namespace boost { namespace pfr { namespace detail {
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;
22 static constexpr std::size_t size() noexcept { return N; }
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) {
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) {
38 std::size_t unclosed_parnthesis = 0;
39 std::size_t count = 0;
41 if (data[from] == opening_parenthis) {
42 ++ unclosed_parnthesis;
43 } else if (data[from] == closing_parenthis) {
44 -- unclosed_parnthesis;
48 if (unclosed_parnthesis == 0) {
58 struct size_array<0> { // libc++ misses constexpr on operator[]
59 typedef std::size_t type;
62 static constexpr std::size_t size() noexcept { return 0; }
64 constexpr std::size_t count_nonzeros() const noexcept {
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");
77 }}} // namespace boost::pfr::detail
79 #endif // BOOST_PFR_DETAIL_SIZE_ARRAY_HPP