| 26 | |
| 27 | template <typename T, typename Allocator> |
| 28 | class array_storage { |
| 29 | public: |
| 30 | using allocator_type = Allocator; |
| 31 | using element_type = T; |
| 32 | using const_reference = const T&; |
| 33 | |
| 34 | private: |
| 35 | using array_type = std::vector<element_type, allocator_type>; |
| 36 | |
| 37 | public: |
| 38 | array_storage(const array_storage&) = default; |
| 39 | array_storage& operator=(const array_storage&) = default; |
| 40 | array_storage(array_storage&&) = default; |
| 41 | array_storage& operator=(array_storage&&) = default; |
| 42 | |
| 43 | template <typename S, typename = detail::requires_storage<S>> |
| 44 | explicit array_storage(const S& o) : array_(o.get_allocator()) { |
| 45 | array_.reserve(o.size()); |
| 46 | for (std::size_t i = 0; i < o.size(); ++i) |
| 47 | array_.emplace_back(static_cast<element_type>(o[i])); |
| 48 | } |
| 49 | |
| 50 | template <typename S, typename = detail::requires_storage<S>> |
| 51 | array_storage& operator=(const S& o) { |
| 52 | array_ = array_type(o.get_allocator()); |
| 53 | array_.reserve(o.size()); |
| 54 | for (std::size_t i = 0; i < o.size(); ++i) |
| 55 | array_.emplace_back(static_cast<element_type>(o[i])); |
| 56 | return *this; |
| 57 | } |
| 58 | |
| 59 | explicit array_storage(const allocator_type& a = allocator_type()) : array_(a) {} |
| 60 | |
| 61 | allocator_type get_allocator() const { return array_.get_allocator(); } |
| 62 | |
| 63 | void reset(std::size_t s) { |
| 64 | if (s == size()) { |
| 65 | std::fill(array_.begin(), array_.end(), element_type(0)); |
| 66 | } else { |
| 67 | array_ = array_type(s, element_type(0), array_.get_allocator()); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | std::size_t size() const noexcept { return array_.size(); } |
| 72 | |
| 73 | void increase(std::size_t i) noexcept { |
| 74 | BOOST_ASSERT(i < size()); |
| 75 | ++array_[i]; |
| 76 | } |
| 77 | |
| 78 | template <typename U> |
| 79 | void add(std::size_t i, const U& x) noexcept { |
| 80 | BOOST_ASSERT(i < size()); |
| 81 | array_[i] += x; |
| 82 | } |
| 83 | |
| 84 | const_reference operator[](std::size_t i) const noexcept { |
| 85 | BOOST_ASSERT(i < size()); |
nothing calls this directly
no test coverage detected