最終更新日時:
が更新

履歴 編集

function
<hive>

std::hive::コンストラクタ(C++26)

constexpr hive() noexcept(noexcept(Allocator()));   // (1) C++26
constexpr explicit hive(const Allocator&) noexcept; // (2) C++26

constexpr explicit hive(hive_limits block_limits);  // (3) C++26
constexpr hive(hive_limits block_limits,
               const Allocator&);                   // (4) C++26

explicit hive(size_type n,
              const Allocator& = Allocator());      // (5) C++26
hive(size_type n, hive_limits block_limits,
     const Allocator& = Allocator());               // (6) C++26

hive(size_type n, const T& value,
     const Allocator& = Allocator());               // (7) C++26
hive(size_type n, const T& value, hive_limits block_limits,
     const Allocator& = Allocator());               // (8) C++26

template <class InputIterator>
hive(InputIterator first, InputIterator last,
     const Allocator& = Allocator());               // (9) C++26
template <class InputIterator>
hive(InputIterator first, InputIterator last, hive_limits block_limits,
     const Allocator& = Allocator());               // (10) C++26

template <container-compatible-range<T> R>
hive(from_range_t, R&& rg,
     const Allocator& = Allocator());               // (11) C++26
template <container-compatible-range<T> R>
hive(from_range_t, R&& rg, hive_limits block_limits,
     const Allocator& = Allocator());               // (12) C++26

hive(const hive& x); // (13) C++26
hive(hive&&) noexcept; // (14) C++26

hive(const hive& x,
     const type_identity_t<Allocator>& alloc); // (15) C++26
hive(hive&&,
     const type_identity_t<Allocator>& alloc); // (16) C++26

hive(initializer_list<T> il,
     const Allocator& = Allocator());               // (17) C++26
hive(initializer_list<T> il, hive_limits block_limits,
     const Allocator& = Allocator());               // (18) C++26

概要

hiveオブジェクトを構築する。

  • (1) : デフォルトコンストラクタ。アロケータをデフォルト構築して、空のhiveを構築する。
  • (2) : アロケータを指定して、空のhiveを構築する。
  • (3) : 要素ブロックの容量制限を指定して、空のhiveを構築する。
  • (4) : 要素ブロックの容量制限とアロケータを指定して、空のhiveを構築する。
  • (5) : n個のデフォルト挿入された要素を保持するhiveを構築する。
  • (6) : (5)に加えて、要素ブロックの容量制限を指定する。
  • (7) : valueのコピーをn個要素として保持するhiveを構築する。
  • (8) : (7)に加えて、要素ブロックの容量制限を指定する。
  • (9) : イテレータ範囲[first, last)を要素としてコピーしたhiveを構築する。
  • (10) : (9)に加えて、要素ブロックの容量制限を指定する。
  • (11) : Rangergの要素でhiveを構築する。
  • (12) : (11)に加えて、要素ブロックの容量制限を指定する。
  • (13) : コピーコンストラクタ。xと同じ要素を保持するhiveを構築する。
  • (14) : ムーブコンストラクタ。xの指す先を自分の領域としてhiveを構築する。
  • (15) : アロケータを指定したコピーコンストラクタ。
  • (16) : アロケータを指定したムーブコンストラクタ。
  • (17) : 初期化子リストを受け取るコンストラクタ。ilの要素でhiveを構築する。
  • (18) : (17)に加えて、要素ブロックの容量制限を指定する。

hive_limitsを受け取るオーバーロード ((3), (4), (6), (8), (10), (12), (18)) は、指定した容量制限で説明専用メンバcurrent-limitsを初期化する。block_limitsがハード制限 (block_capacity_hard_limits) の範囲外であるか、block_limits.min > block_limits.maxである場合、その動作はエラー性動作 (erroneous behavior) であり、効果は処理系定義である。

事前条件

  • (5), (6) : 型Thiveに対してDefaultInsertableであること。
  • (7), (8), (13), (15), (17), (18) : 型Thiveに対してCopyInsertableであること。
  • (16) : allocator_traits<Allocator>::is_always_equal::valuefalseである場合、型Thiveに対してMoveInsertableであること。

効果

  • (14), (16) (alloc == x.get_allocator()trueの場合) : xの各要素ブロックを*thisへ移動する。xの要素を指すポインタ・参照は、*thisのメンバとなった同じ要素を指し続ける。xの要素を指すイテレータは、それらの要素を指し続けるが、*thisのイテレータとして振る舞う。
  • (16) (alloc == x.get_allocator()falseの場合) : xの各要素を*thisへ移動する。xの要素を指す参照・ポインタ・イテレータ、およびxの終端イテレータは無効になる。

事後条件

  • (14), (16) : x.empty() == trueとなる。*thisの要素の相対順序は、呼び出し前のxの要素の相対順序と同じである。

計算量

  • (1), (2), (3), (4) : 定数時間
  • (5), (6), (7), (8) : nに対して線形時間
  • (9), (10) : distance(first, last)に対して線形時間
  • (11), (12) : ranges::distance(rg)に対して線形時間
  • (13), (15) : x.size()に対して線形時間
  • (14) : 定数時間
  • (16) : alloc == x.get_allocator()falseであればx.size()に対して線形時間。そうでなければ定数時間
  • (17), (18) : il.size()に対して線形時間

備考

  • (13), (15) : xcurrent-limits*thiscurrent-limitsを初期化する。
  • (14), (16) : xの各要素ブロックを移動する場合、current-limitsxのものに設定される。

#include <hive>
#include <iterator>
#include <print>

int main()
{
  // デフォルト構築
  std::hive<int> h1;

  // n個の値を保持する
  std::hive<int> h2(3, 1);

  // イテレータ範囲から構築
  int a[] = {1, 2, 3};
  std::hive<int> h3(std::begin(a), std::end(a));

  // 初期化子リストから構築
  std::hive<int> h4 = {1, 2, 3};

  // コピー構築
  std::hive<int> h5 = h4;

  std::println("h1.size() = {}", h1.size());
  std::println("h2.size() = {}", h2.size());
  std::println("h3.size() = {}", h3.size());
  std::println("h4.size() = {}", h4.size());
  std::println("h5.size() = {}", h5.size());
}

出力

h1.size() = 0
h2.size() = 3
h3.size() = 3
h4.size() = 3
h5.size() = 3

バージョン

言語

  • C++26

処理系

関連項目

参照