Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

array_transient.hpp
Go to the documentation of this file.
1 //
2 // immer: immutable data structures for C++
3 // Copyright (C) 2016, 2017, 2018 Juan Pedro Bolivar Puente
4 //
5 // This software is distributed under the Boost Software License, Version 1.0.
6 // See accompanying file LICENSE or copy at http://boost.org/LICENSE_1_0.txt
7 //
8 
9 #pragma once
10 
11 #include <immer/memory_policy.hpp>
13 
14 namespace immer {
15 
16 template <typename T, typename MemoryPolicy>
17 class array;
18 
29 template <typename T, typename MemoryPolicy = default_memory_policy>
30 class array_transient
31  : MemoryPolicy::transience_t::owner
32 {
35  using owner_t = typename MemoryPolicy::transience_t::owner;
36 
37 public:
38  using value_type = T;
39  using reference = const T&;
41  using difference_type = std::ptrdiff_t;
42  using const_reference = const T&;
43 
44  using iterator = const T*;
46  using reverse_iterator = std::reverse_iterator<iterator>;
47 
48  using memory_policy = MemoryPolicy;
50 
56  array_transient() = default;
57 
63  iterator begin() const { return impl_.data(); }
64 
69  iterator end() const { return impl_.data() + impl_.size; }
70 
77 
84 
89  std::size_t size() const { return impl_.size; }
90 
95  bool empty() const { return impl_.d->empty(); }
96 
100  const T* data() const { return impl_.data(); }
101 
105  const T& back() const { return data()[size() - 1]; }
106 
110  const T& front() const { return data()[0]; }
111 
119  { return impl_.get(index); }
120 
127  reference at(size_type index) const
128  { return impl_.get_check(index); }
129 
134  void push_back(value_type value)
135  { impl_.push_back_mut(*this, std::move(value)); }
136 
143  void set(size_type index, value_type value)
144  { impl_.assoc_mut(*this, index, std::move(value)); }
145 
153  template <typename FnT>
154  void update(size_type index, FnT&& fn)
155  { impl_.update_mut(*this, index, std::forward<FnT>(fn)); }
156 
162  void take(size_type elems)
163  { impl_.take_mut(*this, elems); }
164 
170  {
171  this->owner_t::operator=(owner_t{});
172  return persistent_type{ impl_ };
173  }
175  { return persistent_type{ std::move(impl_) }; }
176 
177 private:
179 
181  : impl_(std::move(impl))
182  {}
183 
185 };
186 
187 } // namespace immer
void push_back(value_type value)
void push_back_mut(edit_t e, T value)
const T & front() const
iterator begin() const
reference at(size_type index) const
const T & get_check(std::size_t index) const
Definition: box.hpp:161
void take(size_type elems)
void take_mut(edit_t e, std::size_t sz)
void assoc_mut(edit_t e, std::size_t idx, T value)
persistent_type persistent() &
std::size_t size_t
Definition: bits.hpp:21
const T * data() const
const T & back() const
std::reverse_iterator< iterator > reverse_iterator
typename MemoryPolicy::transience_t::owner owner_t
persistent_type persistent() &&
static const with_capacity & empty()
const T & get(std::size_t index) const
reverse_iterator rbegin() const
void update_mut(edit_t e, std::size_t idx, Fn &&op)
std::ptrdiff_t difference_type
reverse_iterator rend() const
reference operator[](size_type index) const
std::size_t size() const
void update(size_type index, FnT &&fn)
Released under the MIT license