Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:43:38

0001 // Copyright (c) 2016-2023 Antony Polukhin
0002 //
0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_PFR_DETAIL_SIZE_ARRAY_HPP
0007 #define BOOST_PFR_DETAIL_SIZE_ARRAY_HPP
0008 #pragma once
0009 
0010 #include <boost/pfr/detail/config.hpp>
0011 
0012 #include <cstddef>      // metaprogramming stuff
0013 
0014 namespace boost { namespace pfr { namespace detail {
0015 
0016 ///////////////////// Array that has the constexpr
0017 template <std::size_t N>
0018 struct size_array {                         // libc++ misses constexpr on operator[]
0019     typedef std::size_t type;
0020     std::size_t data[N];
0021 
0022     static constexpr std::size_t size() noexcept { return N; }
0023 
0024     constexpr std::size_t count_nonzeros() const noexcept {
0025         std::size_t count = 0;
0026         for (std::size_t i = 0; i < size(); ++i) {
0027             if (data[i]) {
0028                 ++ count;
0029             }
0030         }
0031         return count;
0032     }
0033 
0034     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 {
0035         if (data[from] != opening_parenthis) {
0036             return 0;
0037         }
0038         std::size_t unclosed_parnthesis = 0;
0039         std::size_t count = 0;
0040         for (; ; ++from) {
0041             if (data[from] == opening_parenthis) {
0042                 ++ unclosed_parnthesis;
0043             } else if (data[from] == closing_parenthis) {
0044                 -- unclosed_parnthesis;
0045             }
0046             ++ count;
0047 
0048             if (unclosed_parnthesis == 0) {
0049                 return count;
0050             }
0051         }
0052 
0053         return count;
0054     }
0055 };
0056 
0057 template <>
0058 struct size_array<0> {                         // libc++ misses constexpr on operator[]
0059     typedef std::size_t type;
0060     std::size_t data[1];
0061 
0062     static constexpr std::size_t size() noexcept { return 0; }
0063 
0064     constexpr std::size_t count_nonzeros() const noexcept {
0065         return 0;
0066     }
0067 };
0068 
0069 template <std::size_t I, std::size_t N>
0070 constexpr std::size_t get(const size_array<N>& a) noexcept {
0071     static_assert(I < N, "====================> Boost.PFR: Array index out of bounds");
0072     return a.data[I];
0073 }
0074 
0075 
0076 
0077 }}} // namespace boost::pfr::detail
0078 
0079 #endif // BOOST_PFR_DETAIL_SIZE_ARRAY_HPP