void merge(list& x); // (1) C++98
constexpr void merge(list& x); // (1) C++26
void merge(list&& x); // (2) C++11
constexpr void merge(list&& x); // (2) C++26
template <class Compare>
void
merge(list& x, Compare comp); // (3) C++98
template <class Compare>
constexpr void
merge(list& x, Compare comp); // (3) C++26
template <class Compare>
void
merge(list&& x, Compare comp); // (4) C++11
template <class Compare>
constexpr void
merge(list&& x, Compare comp); // (4) C++26
概要
2つのlistオブジェクトを併合する。
要件
compが狭義の弱順序として定義されていること。*thisとxがその順序でソートされていること。
効果
addressof(x) == thisである場合、何もしない。- そうでない場合、
xを*thisにマージする。2つのlistオブジェクトの要素を*thisに併合し、xはマージ後に空となる。 - マージ後、
xの要素に対するイテレータおよび参照は無効にならない。
戻り値
なし
例外
計算量
高々distance(begin(), end()) + distance(x.begin(), x.end()) - 1回の比較
備考
- この操作は安定である。
- 移動先と移動元のアロケータが等値でない場合(
get_allocator() != x.get_allocator()の場合)、動作は未定義である。
例
出力
1
2
3
4
5
6
参照
- P3372R3 constexpr containers and adaptors
- LWG Issue 1215.
list::mergewith unequal allocators- C++11で、
&x == thisである場合は何もしないことが明記され、アロケータが等値でない場合の動作は未定義であることが規定された
- C++11で、