std::multiset<Key,Compare,Allocator>::insert_range
來自 cppreference.com
template< container-compatible-range<value_type> R > void insert_range( R&& rg ); |
(C++23 起) | |
插入範圍 rg 中每個元素的副本。
範圍 rg 中的每個迭代器都恰好解引用一次。如果 rg 與容器重疊,則行為未定義。
迭代器或引用均未失效。
目錄 |
[編輯] 引數
rg | - | 一個 容器兼容範圍 (container compatible range),即一個其元素可轉換為 T 的 input_range 。 |
型別要求 | ||
-value_type 必須能夠從 *ranges::begin(rg) EmplaceConstructible 到 multiset 中。否則,行為未定義。 |
[編輯] 返回值
(無)
[編輯] 複雜度
N·log(a.size() + N),其中 N
是 ranges::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) |