25 std::unique_ptr<internal::life> elems_life_;
31 void init_elems_life() {
33 elems_life_ = std::unique_ptr<internal::life>(
36 elems_life_ = std::unique_ptr<internal::life>(
45 void update_elems_life(
const void *invalidate_from =
nullptr) {
47 elems_life_->update(&base_[0], &base_[0] + base_.size(),
50 elems_life_->update(
nullptr,
nullptr);
54 const std::string &type_name()
const {
55 return internal::get_type_name<vector>();
57 const std::string &iter_name()
const {
58 static std::string name =
59 internal::get_type_name<vector>() +
"::iterator";
64 const std::string &func,
70 if (base_.size() == 0) {
78 const std::string &func,
84 if (base_.size() == 0) {
95 vector() : base_(), life_(this) { init_elems_life(); }
110 : base_(std::move(other.base_)),
111 elems_life_(std::move(other.elems_life_)), life_(this) {}
119 this->base_ = other.base_;
131 if (
this != std::addressof(other)) {
132 this->base_ = std::move(other.base_);
133 this->elems_life_ = std::move(other.elems_life_);
152 vector(
const std::vector<T> &other) : base_(other), life_(this) {
159 : base_(std::move(other)), life_(this) {
180 this->base_ = std::move(other);
200 template <
typename InputIt>
201 vector(InputIt first, InputIt last) : base_(first, last), life_(this) {
207 vector(std::initializer_list<T> init) : base_(init), life_(this) {
228 base_.assign(count, value);
237 template <
typename InputIt>
238 void assign(InputIt first, InputIt last) {
239 base_.assign(first, last);
248 void assign(std::initializer_list<T> ilist) {
270 base_.reserve(new_cap);
280 base_.shrink_to_fit();
294 static std::string func = type_name() +
"::erase()";
295 std::size_t index = assert_iter(pos, func);
296 base_.erase(base_.begin() + index);
297 update_elems_life(&base_[0] + index);
298 return iterator(&base_[0] + index, elems_life_->observer(),
312 static std::string func = type_name() +
"::erase()";
320 base_.erase(base_.begin() + index_begin, base_.begin() + index_end);
321 update_elems_life(&base_[0] + index_begin);
322 return iterator(&base_[0] + index_begin, elems_life_->observer(),
334 base_.push_back(value);
346 base_.push_back(std::move(value));
357 template <
typename... Args>
359 base_.emplace_back(std::forward<Args>(args)...);
377 static std::string func = type_name() +
"::insert()";
378 std::size_t index = assert_iter_including_end(pos, func);
379 base_.insert(base_.begin() + index, value);
380 update_elems_life(&base_[0] + index);
381 return iterator(&base_[0] + index, elems_life_->observer(),
397 static std::string func = type_name() +
"::insert()";
398 std::size_t index = assert_iter_including_end(pos, func);
399 base_.insert(base_.begin() + index, std::move(value));
400 update_elems_life(&base_[0] + index);
401 return iterator(&base_[0] + index, elems_life_->observer(),
418 static std::string func = type_name() +
"::insert()";
419 std::size_t index = assert_iter_including_end(pos, func);
420 base_.insert(base_.begin() + index, count, std::move(value));
421 update_elems_life(&base_[0] + index);
422 return iterator(&base_[0] + index, elems_life_->observer(),
436 template <
typename InputIt,
437 typename std::enable_if<
439 typename std::iterator_traits<InputIt>::reference,
441 std::nullptr_t>::type =
nullptr>
444 static std::string func = type_name() +
"::insert()";
445 std::size_t index = assert_iter_including_end(pos, func);
446 base_.insert(base_.begin() + index, first, last);
447 update_elems_life(&base_[0] + index);
448 return iterator(&base_[0] + index, elems_life_->observer(),
464 static std::string func = type_name() +
"::insert()";
465 std::size_t index = assert_iter_including_end(pos, func);
466 base_.insert(base_.begin() + index, ilist);
467 update_elems_life(&base_[0] + index);
468 return iterator(&base_[0] + index, elems_life_->observer(),
482 template <
typename... Args,
typename = internal::skip_trace_tag>
484 static std::string func = type_name() +
"::emplace()";
485 std::size_t index = assert_iter_including_end(pos, func);
486 base_.emplace(base_.begin() + index, std::forward<Args>(args)...);
487 update_elems_life(&base_[0] + index);
488 return iterator(&base_[0] + index, elems_life_->observer(),
512 base_.resize(count, value);
524 static std::string func = type_name() +
"::pop_back()";
538 if (n >= base_.size()) {
539 static std::string func = type_name() +
"::at()";
541 static_cast<std::ptrdiff_t
>(n));
543 return reference(&this->base_[n], elems_life_->observer());
552 if (n >= base_.size()) {
553 static std::string func = type_name() +
"::at()";
555 static_cast<std::ptrdiff_t
>(n));
565 template <
typename =
internal::skip_trace_tag>
567 if (n >= base_.size()) {
568 static std::string func = type_name() +
"::operator[]()";
570 func, base_.size(),
static_cast<std::ptrdiff_t
>(n));
572 return reference(&this->base_[n], elems_life_->observer());
580 template <
typename =
internal::skip_trace_tag>
582 if (n >= base_.size()) {
583 static std::string func = type_name() +
"::operator[]()";
585 func, base_.size(),
static_cast<std::ptrdiff_t
>(n));
597 static std::string func = type_name() +
"::front()";
600 return reference(&base_.front(), elems_life_->observer());
610 static std::string func = type_name() +
"::front()";
623 static std::string func = type_name() +
"::back()";
626 return reference(&base_.back(), elems_life_->observer());
636 static std::string func = type_name() +
"::back()";
650 return pointer(
nullptr, elems_life_->observer());
652 return pointer(&this->base_[0], elems_life_->observer());
664 return const_pointer(&this->base_[0], elems_life_->observer());
675 return iterator(
nullptr, elems_life_->observer(), &iter_name());
677 return iterator(&this->base_.front(), elems_life_->observer(),
691 return const_iterator(&this->base_.front(), elems_life_->observer(),
726 bool empty()
const {
return base_.empty(); }
747 base_.swap(other.base_);
748 elems_life_.swap(other.elems_life_);
749 update_elems_life(&base_[0] + base_.size());
750 other.update_elems_life(&other.base_[0] + other.base_.size());
756 operator const std::vector<T> &()
const noexcept {
return base_; }
768 return static_cast<const std::vector<T> &
>(wrapper);
array, vector など各種コンテナのイテレータ
Definition iterator.h:26
const life_observer & get_observer_() const
Definition iterator.h:108
void assert_range_iter(const contiguous_iterator< element_type > &begin, const contiguous_iterator< element_type > &end, const std::string &func, internal::skip_trace_tag={}) const
Definition life.h:173
element_type * assert_iter_including_end(const contiguous_iterator< element_type > &iter, const std::string &func, internal::skip_trace_tag={}) const
Definition life.h:152
element_type * assert_iter(const contiguous_iterator< element_type > &iter, const std::string &func, internal::skip_trace_tag={}) const
Definition life.h:130
オブジェクトのライフタイムを管理するクラス
Definition life.h:207
life_observer observer() const
Definition life.h:233
Definition terminate.h:179
可変長配列 (std::vector)
Definition vector.h:23
vector(std::initializer_list< T > init)
std::initializer_listで初期化
Definition vector.h:207
iterator insert(const_iterator pos, InputIt first, InputIt last, internal::skip_trace_tag={})
要素の挿入
Definition vector.h:442
const_reference at(size_type n, internal::skip_trace_tag={}) const
要素アクセス(const)
Definition vector.h:551
vector & operator=(std::vector< T > &&other)
std::vectorからのムーブ代入
Definition vector.h:179
void resize(size_type count)
サイズを変更
Definition vector.h:499
const_iterator begin() const
先頭要素を指すconstイテレータを取得
Definition vector.h:686
void assign(std::initializer_list< T > ilist)
initializer_listで要素を置き換える
Definition vector.h:248
reference front(internal::skip_trace_tag={})
先頭の要素へのアクセス
Definition vector.h:595
const_pointer data() const
先頭要素へのconstポインタを取得
Definition vector.h:660
pointer data()
先頭要素へのポインタを取得
Definition vector.h:648
reference operator[](size_type n)
要素アクセス
Definition vector.h:566
const_iterator cbegin() const
先頭要素を指すconstイテレータを取得
Definition vector.h:700
reference at(size_type n, internal::skip_trace_tag={})
要素アクセス
Definition vector.h:537
void swap(vector &other)
別のvectorと要素を入れ替える
Definition vector.h:746
iterator erase(const_iterator pos, internal::skip_trace_tag={})
要素の削除
Definition vector.h:293
iterator insert(const_iterator pos, size_type count, const T &value, internal::skip_trace_tag={})
要素の挿入
Definition vector.h:416
iterator insert(const_iterator pos, const T &value, internal::skip_trace_tag={})
要素の挿入
Definition vector.h:375
void shrink_to_fit()
容量の縮小
Definition vector.h:279
size_type size() const
配列のサイズを取得
Definition vector.h:730
vector & operator=(vector &&other)
すべての要素をムーブ
Definition vector.h:130
bool empty() const
sizeが0かどうかを返す
Definition vector.h:726
void push_back(const T &value)
要素の追加
Definition vector.h:333
internal::contiguous_iterator< T > iterator
Definition vector.h:146
wrap< const vector * > operator&() const
Definition vector.h:761
vector(const vector &other)
新しい領域にコピー構築
Definition vector.h:99
iterator emplace(const_iterator pos, Args &&...args)
要素の挿入
Definition vector.h:483
void reserve(size_type new_cap)
領域の確保
Definition vector.h:269
vector(const std::vector< T > &other)
std::vectorからコピー構築
Definition vector.h:152
vector(vector &&other)
ムーブ構築
Definition vector.h:109
const_iterator cend() const
末尾要素を指すconstイテレータを取得
Definition vector.h:721
size_type max_size() const
配列の最大サイズを取得
Definition vector.h:734
wrap_ref< T > reference
Definition vector.h:142
vector & operator=(std::initializer_list< T > ilist)
initialization_listの代入
Definition vector.h:215
void push_back(T &&value)
要素の追加
Definition vector.h:345
void assign(size_type count, const T &value)
サイズと値を指定して要素を置き換える
Definition vector.h:227
vector(size_type count)
サイズ指定して初期化
Definition vector.h:188
vector(InputIt first, InputIt last)
イテレータで初期化
Definition vector.h:201
void assign(InputIt first, InputIt last)
イテレータからのコピーで要素を置き換える
Definition vector.h:238
reference emplace_back(Args &&...args)
要素の追加
Definition vector.h:358
reference back(internal::skip_trace_tag={})
末尾の要素へのアクセス
Definition vector.h:621
vector & operator=(const vector &other)
すべての要素をコピー
Definition vector.h:118
ptr< T > pointer
Definition vector.h:144
iterator insert(const_iterator pos, T &&value, internal::skip_trace_tag={})
要素の挿入
Definition vector.h:395
const_reference back(internal::skip_trace_tag={}) const
末尾の要素へのアクセス(const)
Definition vector.h:634
const_ptr< T > const_pointer
Definition vector.h:145
vector & operator=(const std::vector< T > &other)
std::vectorからのコピー代入
Definition vector.h:168
internal::contiguous_iterator< const T > const_iterator
Definition vector.h:147
vector(const std::vector< T > &&other)
std::vectorからムーブ構築
Definition vector.h:158
void clear()
要素のクリア
Definition vector.h:258
iterator end()
末尾要素を指すイテレータを取得
Definition vector.h:707
iterator erase(const_iterator begin, const_iterator end, internal::skip_trace_tag={})
要素の削除
Definition vector.h:310
void pop_back(internal::skip_trace_tag={})
末尾の要素を削除
Definition vector.h:522
const_iterator end() const
末尾要素を指すconstイテレータを取得
Definition vector.h:714
std::ptrdiff_t difference_type
Definition vector.h:141
size_type capacity() const
現在のメモリ確保済みのサイズを取得
Definition vector.h:738
iterator begin()
先頭要素を指すイテレータを取得
Definition vector.h:673
const_wrap_ref< T > const_reference
Definition vector.h:143
vector(size_type count, const T &value)
サイズと値を指定して初期化
Definition vector.h:194
vector()
サイズ0のvectorを作成する
Definition vector.h:95
iterator insert(const_iterator pos, std::initializer_list< T > ilist, internal::skip_trace_tag={})
要素の挿入
Definition vector.h:462
const_reference front(internal::skip_trace_tag={}) const
先頭の要素へのアクセス(const)
Definition vector.h:608
const_reference operator[](size_type n) const
要素アクセス(const)
Definition vector.h:581
std::size_t size_type
Definition vector.h:140
T value_type
Definition vector.h:139
void resize(size_type count, const T &value)
サイズを変更
Definition vector.h:511
ポインタ型wrap: element_type型のデータへのポインタと、 このポインタ自体の生存状態を管理するクラス
Definition wrap.h:318
参照型wrap: element_type型のデータへの参照を持つクラス
Definition wrap.h:168
値型wrap: base_type型のデータと、このデータの生存状態を管理するクラス
Definition wrap.h:26
void terminate_ub_wrong_iter(std::string func, Args &&...args)
Definition terminate.h:135
element_type * unwrap(const contiguous_iterator< element_type > &wrapper) noexcept
Definition iterator.h:209
void terminate_ub_out_of_range(std::string func, Args &&...args)
Definition terminate.h:132
bool operator!=(const array< T, N > &lhs, const array< T, N > &rhs)
Definition array.h:390
bool operator<=(const array< T, N > &lhs, const array< T, N > &rhs)
Definition array.h:398
void swap(array< T, N > &lhs, array< T, N > &rhs)
Definition array.h:381
bool operator==(const array< T, N > &lhs, const array< T, N > &rhs)
Definition array.h:386
std::array< T, N > & unwrap(array< T, N > &wrapper) noexcept
Definition array.h:372
bool operator>(const array< T, N > &lhs, const array< T, N > &rhs)
Definition array.h:402
bool operator<(const array< T, N > &lhs, const array< T, N > &rhs)
Definition array.h:394
bool operator>=(const array< T, N > &lhs, const array< T, N > &rhs)
Definition array.h:406
Definition terminate.h:27