Namespaces
Variants

std::inplace_vector<T,N>::append_range

ja.cppreference.net より

 
 
 
 
template< container-compatible-range<T> R >
constexpr void append_range( R&& rg );
(C++26以上)

範囲 rg の要素のコピーを end() の前に非逆順で挿入します。


内の各イテレータは rg ちょうど1回だけ逆参照されます。

パラメータ

rg - a container compatible range , that is, an input_range whose elements are convertible to T
Type requirements
-
If T is not EmplaceConstructible into inplace_vector from * ranges:: begin ( rg ) , the behavior is undefined.

計算量

rg のサイズに対して線形。 T のコンストラクタの呼び出し回数は厳密に std :: ranges:: size ( rg ) ) と等しい。

例外

std::bad_alloc をスローする( std :: ranges:: size ( rg ) > N の場合)。 T のコピーコンストラクタ、ムーブコンストラクタ、代入演算子、ムーブ代入演算子、または任意の InputIterator 操作以外で例外がスローされた場合、効果はない。 それ以外の場合、例外がスローされたときは size ( ) >= n であり、範囲 [ ​ 0 ​ , n ) 内の要素は変更されない。 ここで n はこの呼び出し前の size() の値である。

例

#include <cassert>
#include <inplace_vector>
#include <iostream>
int main()
{
    using I = std::inplace_vector<int, 8>;
    auto head = I{1, 2, 3, 4};
    const auto tail = {-5, -6, -7};
    head.append_range(tail);
    assert(head.size() == 7 and (head == I{1, 2, 3, 4, -5, -6, -7}));
    try
    {
        head.append_range(tail); // スロー: 空き領域なし
    }
    catch(const std::bad_alloc&)
    {
        std::cout << "std::bad_alloc\n";
    }
}

出力:

std::bad_alloc

関連項目

要素の範囲を挿入する
(パブリックメンバ関数)
末尾に要素を追加する
(パブリックメンバ関数)
末尾に要素を直接構築する
(パブリックメンバ関数)