名稱空間
變體
操作

std::multiset<Key,Compare,Allocator>::insert_range

來自 cppreference.com
< cpp‎ | 容器‎ | multiset
 
 
 
 
template< container-compatible-range<value_type> R >
void insert_range( R&& rg );
(C++23 起)

插入範圍 rg 中每個元素的副本。

範圍 rg 中的每個迭代器都恰好解引用一次。如果 rg 與容器重疊,則行為未定義。

迭代器或引用均未失效。

目錄

[編輯] 引數

rg - 一個 容器兼容範圍 (container compatible range),即一個其元素可轉換為 Tinput_range
型別要求
-
value_type 必須能夠從 *ranges::begin(rg) EmplaceConstructiblemultiset 中。否則,行為未定義。

[編輯] 返回值

(無)

[編輯] 複雜度

N·log(a.size() + N),其中 Nranges::distance(rg)

[編輯] 注意

特性測試 標準 特性
__cpp_lib_containers_ranges 202202L (C++23) 範圍感知(Ranges-aware)構造和插入

[編輯] 示例

#include <iostream>
#include <set>
 
void println(auto, auto const& container)
{
    for (const auto& elem : container)
        std::cout << elem << ' ';
    std::cout << '\n';
}
 
int main()
{
    auto container = std::multiset{1, 3, 2, 4};
    const auto rg = {-1, 3, -2};
#ifdef __cpp_lib_containers_ranges
    container.insert_range(rg);
#else
    container.insert(rg.begin(), rg.end());
#endif
    println("{}", container);
}

輸出

-2 -1 1 2 3 3 4

[編輯] 另請參閱

插入元素 或節點(C++17 起)
(public member function) [編輯]