Files
2025-10-25 03:02:53 +03:00

176 lines
5.7 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[flat.set.modifiers]
# 23 Containers library [[containers]](./#containers)
## 23.6 Container adaptors [[container.adaptors]](container.adaptors#flat.set.modifiers)
### 23.6.11 Class template flat_set [[flat.set]](flat.set#modifiers)
#### 23.6.11.5 Modifiers [flat.set.modifiers]
[🔗](#lib:insert,flat_set)
`template<class K> constexpr pair<iterator, bool> insert(K&& x);
template<class K> constexpr iterator insert(const_iterator hint, K&& x);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19283)
*Constraints*: The [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Compare::is_transparent is valid and denotes a type[.](#1.sentence-1)
is_constructible_v<value_type, K> is true[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19289)
*Preconditions*: The conversion from x into value_type constructs
an object u, for which find(x) == find(u) is true[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19294)
*Effects*: If the set already contains an element equivalent to x,*this and x are unchanged[.](#3.sentence-1)
Otherwise,
inserts a new element as if by emplace(std::forward<K>(x))[.](#3.sentence-2)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19301)
*Returns*: In the first overload,
the bool component of the returned pair is true if and only if the insertion took place[.](#4.sentence-1)
The returned iterator points to the element
whose key is equivalent to x[.](#4.sentence-2)
[🔗](#lib:insert,flat_set_)
`template<class InputIterator>
constexpr void insert(InputIterator first, InputIterator last);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19317)
*Effects*: Adds elements to *c* as if by:*c*.insert(*c*.end(), first, last);
Then,
sorts the range of newly inserted elements with respect to *compare*;
merges the resulting sorted range and
the sorted range of pre-existing elements into a single sorted range; and
finally erases all but the first element
from each group of consecutive equivalent elements[.](#5.sentence-2)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19330)
*Complexity*: N + MlogM, where N is size() before the operation andM is distance(first, last)[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19335)
*Remarks*: Since this operation performs an in-place merge, it may allocate memory[.](#7.sentence-1)
[🔗](#lib:insert,flat_set__)
`template<class InputIterator>
constexpr void insert(sorted_unique_t, InputIterator first, InputIterator last);
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19347)
*Effects*: Equivalent to insert(first, last)[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19351)
*Complexity*: Linear[.](#9.sentence-1)
[🔗](#lib:insert_range,flat_set)
`template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<value_type> R>
constexpr void insert_range(R&& rg);
`
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19363)
*Effects*: Adds elements to *c* as if by:for (const auto& e : rg) {*c*.insert(*c*.end(), e);}
Then,
sorts the range of newly inserted elements with respect to *compare*;
merges the resulting sorted range and
the sorted range of pre-existing elements into a single sorted range; and
finally erases all but the first element
from each group of consecutive equivalent elements[.](#10.sentence-2)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19378)
*Complexity*: N + MlogM, where N is size() before the operation and M is ranges::distance(rg)[.](#11.sentence-1)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19383)
*Remarks*: Since this operation performs an in-place merge, it may allocate memory[.](#12.sentence-1)
[🔗](#lib:swap,flat_set)
`constexpr void swap(flat_set& y) noexcept;
`
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19394)
*Effects*: Equivalent to:ranges::swap(*compare*, y.*compare*);
ranges::swap(*c*, y.*c*);
[🔗](#lib:extract,flat_set)
`constexpr container_type extract() &&;
`
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19409)
*Postconditions*: *this is emptied, even if the function exits via an exception[.](#14.sentence-1)
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19413)
*Returns*: std::move(*c*)[.](#15.sentence-1)
[🔗](#lib:replace,flat_set)
`constexpr void replace(container_type&& cont);
`
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19424)
*Preconditions*: The elements of cont are sorted with respect to *compare*, andcont contains no equal elements[.](#16.sentence-1)
[17](#17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L19429)
*Effects*: Equivalent to: *c* = std::move(cont);