Namespaces
Variants

std::flat_set<Key,Compare,KeyContainer>::flat_set

From cppreference.com

[edit template]
 
 
 
 
flat_set()
    : flat_set(key_compare()) {}
(1) (since C++23)
flat_set( const flat_set& other );
(2) (since C++23)
flat_set( flat_set&& other );
(3) (since C++23)
explicit flat_set( const key_compare& comp )
    : c(), compare(comp) {}
(4) (since C++23)
flat_set( container_type cont,
          const key_compare& comp = key_compare() );
(5) (since C++23)
flat_set( std::sorted_unique_t,
          container_type cont,
          const key_compare& comp = key_compare() );
(6) (since C++23)
template< class InputIter >
flat_set( InputIter first, InputIter last,
          const key_compare& comp = key_compare() )
    : c(), compare(comp);
(7) (since C++23)
template< class InputIter >
flat_set( std::sorted_unique_t, InputIter first, InputIter last,
          const key_compare& comp = key_compare() )
    : c(), compare(comp);
(8) (since C++23)
template< container-compatible-range<value_type> R >
flat_set( std::from_range_t, R&& rg )
    : flat_set(std::from_range, std::forward<R>(rg), key_compare()) {}
(9) (since C++23)
template< container-compatible-range<value_type> R >
flat_set( std::from_range_t, R&& rg, const key_compare& comp )
    : flat_set(comp);
(10) (since C++23)
flat_set( std::initializer_list<value_type> init,
          const key_compare& comp = key_compare() )
    : flat_set(init.begin(), init.end(), comp) {}
(11) (since C++23)
flat_set( std::sorted_unique_t,
          std::initializer_list<value_type> init,
          const key_compare& comp = key_compare() )
    : flat_set(std::sorted_unique,
               init.begin(), init.end(), comp) {}
(12) (since C++23)
Constructors with allocators
template< class Allocator >
explicit flat_set( const Allocator& alloc );
(1A) (since C++23)
template< class Allocator >
flat_set( const flat_set& other, const Allocator& alloc );
(2A) (since C++23)
template< class Allocator >
flat_set( flat_set&& other, const Allocator& alloc );
(3A) (since C++23)
template< class Allocator >
flat_set( const key_compare& comp, const Allocator& alloc );
(4A) (since C++23)
template< class Allocator >
flat_set( const container_type& cont,
          const Allocator& alloc );
(5A) (since C++23)
template< class Allocator >
flat_set( const container_type& cont,
          const key_compare& comp, const Allocator& alloc );
(5B) (since C++23)
template< class Allocator >
flat_set( std::sorted_unique_t,
          const container_type& cont,
          const Allocator& alloc );
(6A) (since C++23)
template< class Allocator >
flat_set( std::sorted_unique_t,
          const container_type& cont,
          const key_compare& comp, const Allocator& alloc );
(6B) (since C++23)
template< class InputIter, class Allocator >
flat_set( InputIter first, InputIter last, const Allocator& alloc );
(7A) (since C++23)
template< class InputIter, class Allocator >
flat_set( InputIter first, InputIter last,
          const key_compare& comp, const Allocator& alloc );
(7B) (since C++23)
template< class InputIter, class Allocator >
flat_set( std::sorted_unique_t, InputIter first, InputIter last,
          const Allocator& alloc );
(8A) (since C++23)
template< class InputIter, class Allocator >
flat_set( std::sorted_unique_t, InputIter first, InputIter last,
          const key_compare& comp, const Allocator& alloc );
(8B) (since C++23)
template< container-compatible-range<value_type> R, class Allocator >
flat_set( std::from_range_t, R&& rg, const Allocator& alloc );
(9A) (since C++23)
template< container-compatible-range<value_type> R, class Allocator >
flat_set( std::from_range_t, R&& rg, const key_compare& comp,
          const Allocator& alloc );
(10A) (since C++23)
template< class Allocator >
flat_set( std::initializer_list<value_type> init,
          const Allocator& alloc );
(11A) (since C++23)
template< class Allocator >
flat_set( std::initializer_list<value_type> init,
          const key_compare& comp, const Allocator& alloc );
(11B) (since C++23)
template< class Allocator >
flat_set( std::sorted_unique_t,
          std::initializer_list<value_type> init,
          const Allocator& alloc );
(12A) (since C++23)
template< class Allocator >
flat_set( std::sorted_unique_t,
          std::initializer_list<value_type> init,
          const key_compare& comp, const Allocator& alloc );
(12B) (since C++23)

Constructs new container adaptor from a variety of data sources and optionally using user supplied comparison function object comp and/or allocator alloc.

1) The default constructor. Constructs an empty container adaptor.
2) A copy constructor. Constructs c with the copy of the contents of other.c and compare with other.compare.
3) A move constructor. Constructs the container adaptor with the contents of other using move semantics.
4) Constructs an empty container adaptor.
5) First, initializes c with std::move(cont) and compare with comp.
Then sorts the underlying range [begin(), end()) with respect to compare .
Finally, erases all but the first element from each group of consecutive equivalent elements.
6) First, initializes c with std::move(cont) and compare with comp.
If cont is not sorted with respect to key_comp() or contains equal elements, the behavior is undefined.
7,8) Constructs the container adaptor with the contents of the range [first, last).
If [first, last) is not a valid range, the behavior is undefined.
7) Equivalent to evaluating insert(first, last) after constructing an empty container adaptor.
8) Equivalent to evaluating insert(std::sorted_unique, first, last) after constructing an empty container adaptor.
If [first, last) is not sorted with respect to key_comp() or contains equal elements, the behavior is undefined.
9,10) Constructs the container adaptor with the contents of the range rg.
Equivalent to evaluating insert_range(std::forward<R>(rg)) after constructing an empty container adaptor.
11,12) Constructs the container adaptor with the contents of the initializer list init.
12) If init is not sorted with respect to key_comp() or contains equal elements, the behavior is undefined.

Constructors with allocators are equivalent to the corresponding non-allocator constructors except that c is constructed with uses-allocator construction. These overloads participate in overload resolution only if std::uses_allocator_v<container_type, Allocator> is true.

Parameters

cont - a container to be used as source to initialize the underlying container
other - another flat_set to be used as source to initialize the elements of the underlying container with
alloc - an allocator to use for all memory allocations of the underlying container
comp - a function object to be used for all comparisons of keys
first, last - the pair of iterators defining the source range of elements to copy
init - an initializer list to initialize the elements of the underlying container with
rg - a container compatible range
Type requirements
-
InputIt must meet the requirements of LegacyInputIterator.
-
Compare must meet the requirements of Compare.
-
Allocator must meet the requirements of Allocator.

Complexity

Unless otherwise specified, the complexity requirements on constructors with allocators are the same of those on the corresponding non-allocator constructors.

1) Constant.
2) 𝓞(N), where N is other.size().
3,4) Constant.
5) 𝓞(N) if cont is sorted with respect to compare , otherwise 𝓞(N·log(N)), where N is the value of cont.size() before this call.
6) Constant.
6A,6B) 𝓞(N), where N is the value of cont.size() before this call.
7) 𝓞(N) if [first, last) is sorted with respect to value_comp(), otherwise 𝓞(N·log(N)), where N is std::distance(first, last).
8) 𝓞(N), where N is std::distance(first, last).
9) 𝓞(N) if rg is sorted with respect to value_comp(), otherwise 𝓞(N·log(N)), where N is ranges::distance(rg).
10) 𝓞(N), where N is ranges::distance(rg).
11) 𝓞(N) if init is sorted with respect to value_comp(), otherwise 𝓞(N·log(N)), where N is init.size().
12) 𝓞(N), where N is init.size().

Exceptions

Calls to Allocator::allocate may throw.

Notes

After container move construction (overload (3,3A)), references, pointers, and iterators that originally refer to elements in 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. If multiple elements in the range have keys that compare equivalent, it is unspecified which element is inserted (pending LWG2844).

Example

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
P3567R2 C++23 the copy and move constructors were missing added

See also

assigns values to the container adaptor
(public member function) [edit]