std::flat_set::flat_set(3)
π NAME π
okay so bestie, welcome to std::flat_set::flat_set(3) from the C++ Standard Libary (yep, that spelling is right there and we are respecting it π
). This is part 1 of 2, and the name of the game is:
std::flat_set::flat_set β std::flat_set::flat_set
β¨ Synopsis β¨
bestie, this is the whole overload lineup. all of these are (since C++23), and yes, there are 28 of them. no cap, we're keeping every single one exactly as written:
flat_set() (1)
(since C++23)
: flat_set(key_compare()) { }
template< class Allocator > (2)
(since C++23)
flat_set( const flat_set& other, const Allocator& alloc );
template< class Allocator > (3)
(since C++23)
flat_set( flat_set&& other, const Allocator& alloc );
explicit flat_set( container_type cont, (4)
(since C++23)
const key_compare& comp = key_compare() );
template< class Allocator > (5)
(since C++23)
flat_set( const container_type& cont, const Allocator& alloc );
template< class Allocator >
flat_set( const container_type& cont, const key_compare& comp, (6)
(since C++23)
const Allocator& alloc );
flat_set( std::sorted_unique_t s, container_type cont,
const key_compare& comp = key_compare() ) (7)
(since C++23)
: c(std::move(cont)), compare(comp) { }
template< class Allocator >
flat_set( std::sorted_unique_t s, const container_type& cont, (8)
(since C++23)
const Allocator& alloc );
template< class Allocator >
flat_set( std::sorted_unique_t s, const container_type& cont, (9)
(since C++23)
const key_compare& comp, const Allocator& alloc );
explicit flat_set( const key_compare& comp )
(10) (since C++23)
: c(), compare(comp) { }
template< class Allocator >
(11) (since C++23)
flat_set( const key_compare& comp, const Allocator& alloc );
template< class Allocator >
(12) (since C++23)
explicit flat_set( const Allocator& alloc );
template< class InputIter >
flat_set( InputIter first, InputIter last,
(13) (since C++23)
const key_compare& comp = key_compare() )
: c(), compare(comp);
template< class InputIter, class Allocator >
flat_set( InputIter first, InputIter last,
(14) (since C++23)
const key_compare& comp, const Allocator& alloc );
template< class InputIter, class Allocator >
flat_set( InputIter first, InputIter last, const Allocator& alloc
(15) (since C++23)
);
template< container-compatible-range<value_type> R >
flat_set( std::from_range_t, R&& rg, const key_compare& comp )
(16) (since C++23)
: flat_set(comp);
template< container-compatible-range<value_type> R >
flat_set( std::from_range_t fr, R&& rg )
(17) (since C++23)
: flat_set( fr, std::forward<R>(rg), key_compare() ) { }
template< container-compatible-range<value_type> R, class
Allocator >
(18) (since C++23)
flat_set( std::from_range_t, R&& rg, const Allocator& alloc );
template< container-compatible-range<value_type> R, class
Allocator >
(19)
(since C++23)
flat_set( std::from_range_t, R&& rg, const key_compare& comp,
const Allocator& alloc );
template< class InputIter >
flat_set( std::sorted_unique_t s, InputIter first, InputIter
last,
(20) (since C++23)
const key_compare& comp = key_compare() )
: c(first, last), compare(comp) { }
template< class InputIter, class Allocator >
flat_set( std::sorted_unique_t s, InputIter first, InputIter
(21) (since C++23)
last,
const key_compare& comp, const Allocator& alloc );
template< class InputIter, class Allocator >
flat_set( std::sorted_unique_t s, InputIter first, InputIter
(22) (since C++23)
last,
const Allocator& alloc );
flat_set( std::initializer_list<value_type> init,
const key_compare& comp = key_compare() )
(23) (since C++23)
: flat_set(init.begin(), init.end(), comp) { }
template< class Allocator >
flat_set( std::initializer_list<value_type> init, const
(24) (since C++23)
key_compare& comp,
const Allocator& alloc );
template< class Allocator >
flat_set( std::initializer_list<value_type> init, const
(25) (since C++23)
Allocator& alloc );
flat_set( std::sorted_unique_t s,
std::initializer_list<value_type> init,
(26)
(since C++23)
const key_compare& comp = key_compare() )
: flat_set(s, init.begin(), init.end(), comp) { }
template< class Allocator >
flat_set( std::sorted_unique_t s,
(27) (since C++23)
std::initializer_list<value_type> init,
const key_compare& comp, const Allocator& alloc );
template< class Allocator >
flat_set( std::sorted_unique_t s,
(28) (since C++23)
std::initializer_list<value_type> init,
const Allocator& alloc );
πΈ Description πΈ
okay so the whole vibe here is: construct a new container adaptor from a bunch of different data sources, and you can optionally pass a comparison function object comp and/or an allocator alloc. that's the tea π«β¨
π Overloads, one by one π
(1)β a default constructor. constructs an empty container adaptor. the body is literally: flat_set(key_compare()) { }π(2)β a copy constructor. constructscwith the copy of the contents ofother.candcomparewithother.compare. see allocator usage note below π«Ά(3)β a move constructor. constructs the container adaptor with the contents ofotherusing move semantics. see allocator usage note below π«Ά(4)β constructs the underlying container with the contents of the containercont. first, initializescwithstd::move(cont)andcomparewithcomp. then sorts thecwith respect tocomp. finally, makes elements unique, i.e. erases all but the first element from each group of consecutive equivalent elements. slay, but also read that carefully π₯(5)β same as(4), equivalent toflat_set(cont);. see allocator usage note below π«Ά(6)β same as(4), equivalent toflat_set(cont, comp);. see allocator usage note below π«Ά(7)β constructs the underlying container with the contents of the other containercont. initializescwithstd::move(cont)andcomparewithcomp. the body is: c(std::move(cont)), compare(comp) { }β¨(8)β same as(7), equivalent toflat_set(s, cont);. see allocator usage note below π«Ά(9)β same as(7), equivalent toflat_set(s, cont, comp);. see allocator usage note below π«Ά(10)β constructs an empty container adaptor. the body is: c(), compare(comp) { }π(11,12)β constructs an empty container adaptor. see allocator usage note below π«Ά(13)β constructs the container adaptor with the contents of the range[first, last), equivalent toinsert(first, last);. the body is: c(), compare(comp);π(14,15)β same as(13). see allocator usage note below π«Ά(16)β constructs the container adaptor with the contents of the rangerg. first, uses(10)as delegating constructor. then initializescwith the contents ofrgas if byinsert_range(std::forward<R>(rg));. the body is: flat_set(comp);π¦(17)β same as(16)using it as delegating constructor. the body is: flat_set( fr, std::forward<R>(rg), key_compare() ) { }π(18,19)β same as(16). see allocator usage note below π«Ά(20)β constructs the underlying container with the contents of the range[first, last). initializescwithc(first, last)andcomparewithcompare(comp). the body is: c(first, last), compare(comp) { }β(21,22)β same as(20). see allocator usage note below π«Ά(23)β an initializer-list constructor. constructs the underlying container with the contents of the initializer listinit, using(13)as delegating constructor. the body is: flat_set(init.begin(), init.end(), comp) { }π(24,25)β same as(23). see allocator usage note below π«Ά(26)β an initializer-list constructor. constructs the underlying container with the contents of the initializer listinit, using(20)as delegating constructor. the body is: flat_set(s, init.begin(), init.end(), comp) { }π§(27,28)β Save as(26). see allocator usage note below π«Ά (yes, the page says βSave asβ β we are not fixing it, we are respecting the lore π )
π¨ Note for overloads(13-15,20-22): if[first, last)is not a valid range, the behavior is undefined. literally do not, bestie π
π Note for overloads (4-6,13-19,23-25): if multiple elements in the range have keys that compare equivalent, it is unspecified which element is inserted (pending LWG2844). no cap, that's the caveat π₯
π¦ Parameters π¦
contβ a container to be used as source to initialize the underlying containerotherβ anotherflat_setto be used as source to initialize the elements of the underlying container withallocβ an allocator to use for all memory allocations of the underlying containercompβ a function object to be used for all comparisons of keysfirst, lastβ a range to copy the elements frominitβ an initializer list to initialize the elements of the underlying container withrgβ a container compatible range (that is, aninput_rangewhose elements are convertible tovalue_type) to be used as source to initialize the underlying containerfrβ a disambiguation tag that indicates that the contained member should be range constructedsβ a disambiguation tag that indicates that the input sequence is sorted with respect tocompareand all its elements are unique
π Type requirements π
InputItmust meet the requirements ofLegacyInputIterator.Comparemust meet the requirements ofCompare.Allocatormust meet the requirements ofAllocator.
periodt π β¨
π COMPLEXITY π
okay so here's the complexity tea, bestie β every group is numbered exactly like the original, no cap β¨
1)β Constant. literally just constant π2)β Linear in size ofother.3)β Same as the corresponding move-constructor of the wrapped container, i.e. constant or linear in size ofcont.4-6)β Linear inNifcontis sorted with respect tocompare, otherwiseO(NΒ·log(N)), whereNis the value ofcont.size()before this call.7-9)β Same as the corresponding move-constructor of the wrapped container, i.e. constant or linear in size ofcont.10-12)β Constant. iconic, honestly π13-15)β Linear inNif the input range[first, last)is sorted with respect tocompare, otherwiseO(NΒ·log(N)), whereNis the value ofcont.size()before this call.16-19)β Linear inNif the input rangergis sorted with respect tocompare, otherwiseO(NΒ·log(N)), whereNis the value ofcont.size()before this call.20-22)β Linear in size of[first, last).23-25)β Linear inNif the elements ofinitare sorted with respect tocompare, otherwiseO(NΒ·log(N)), whereNis the value ofcont.size()before this call.26-28)β Linear in size ofinit.
π¨ EXCEPTIONS π¨
Calls to Allocator::allocate may throw. that's it, that's the warning π«Ά
π NOTES π
After container move construction (overload (3,16-19)), references, pointers, and iterators (other than the end iterator) to other remain valid, but refer to elements that are now in *this.
The current standard makes this guarantee via the blanket statement in [container.reqmts]/67, and a more direct guarantee is under consideration via LWG issue 2321. iykyk, standard-nerd lore π
π§ͺ EXAMPLE π§ͺ
This section is incomplete.
Reason: no example.
bestie they really said βno exampleβ and left it at that ππ
π SEE ALSO π
operator=assigns values to the container adaptor (public member function)
π·οΈ CATEGORY
- Todo no example
π source: cppreference.com Β· version 2024.06.10 Β· page std::flat_set::flat_set(3) β mwah, bye bestie! π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms