std::flat_m...lat_multiset(3)

๐Ÿ“ฆ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

๐ŸŽ€ NAME ๐ŸŽ€

std::flat_multiset::flat_multiset โ€” std::flat_multiset::flat_multiset

this is the std::flat_m...lat_multiset(3) page from the C++ Standard Libary (yes, โ€œLibaryโ€, thatโ€™s the headerโ€™s typo, weโ€™re keeping the chaos), and itโ€™s all about constructors for std::flat_multiset. there are literally 28 overloads. twenty-eight. iconic overload count, no cap.

โœจ Synopsis โœจ

every overload here is (since C++23), and the lineup is long enough to need a snack. here it is, verbatim:

          flat_multiset()                                                   (1)
       (since C++23)
              : flat_multiset(key_compare()) { }
          template< class Allocator >
          flat_multiset( const flat_multiset& other, const Allocator& alloc (2)
       (since C++23)
          );
          template< class Allocator >                                       (3)
       (since C++23)
          flat_multiset( flat_multiset&& other, const Allocator& alloc );
          explicit flat_multiset( container_type cont,
                                  const key_compare& comp = key_compare()   (4)
       (since C++23)
          );
          template< class Allocator >
          flat_multiset( const container_type& cont, const Allocator& alloc (5)
       (since C++23)
          );
          template< class Allocator >

          flat_multiset( const container_type& cont, const key_compare&     (6)
       (since C++23)
          comp,

                         const Allocator& alloc );
          flat_multiset( std::sorted_equivalent_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_multiset( std::sorted_equivalent_t s, const container_type&  (8)
       (since C++23)
          cont,

                         const Allocator& alloc );
          template< class Allocator >

          flat_multiset( std::sorted_equivalent_t s, const container_type&  (9)
       (since C++23)
          cont,

                         const key_compare& comp, const Allocator& alloc );
          explicit flat_multiset( const key_compare& comp )
       (10) (since C++23)
              : c(), compare(comp) { }
          template< class Allocator >
       (11) (since C++23)
          flat_multiset( const key_compare& comp, const Allocator& alloc );
          template< class Allocator >
       (12) (since C++23)
          explicit flat_multiset( const Allocator& alloc );
          template< class InputIter >

          flat_multiset( InputIter first, InputIter last,
       (13) (since C++23)
                         const key_compare& comp = key_compare() )

              : c(), compare(comp);
          template< class InputIter, class Allocator >

          flat_multiset( InputIter first, InputIter last,
       (14) (since C++23)

                         const key_compare& comp, const Allocator& alloc );
          template< class InputIter, class Allocator >
          flat_multiset( InputIter first, InputIter last, const Allocator&
       (15) (since C++23)
          alloc );
          template< container-compatible-range<value_type> R >

          flat_multiset( std::from_range_t, R&& rg, const key_compare& comp
       (16) (since C++23)
          )

              : flat_multiset(comp);
          template< container-compatible-range<value_type> R >

          flat_multiset( std::from_range_t fr, R&& rg )
       (17) (since C++23)

              : flat_multiset( fr, std::forward<R>(rg), key_compare() ) { }
          template< container-compatible-range<value_type> R, class
          Allocator >
       (18) (since C++23)
          flat_multiset( std::from_range_t, R&& rg, const Allocator& alloc
          );
          template< container-compatible-range<value_type> R, class
          Allocator >

          flat_multiset( std::from_range_t, R&& rg, const key_compare&
       (19) (since C++23)
          comp,

                         const Allocator& alloc );
          template< class InputIter >

          flat_multiset( std::sorted_equivalent_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_multiset( std::sorted_equivalent_t s, InputIter first,
       (21) (since C++23)
          InputIter last,

                         const key_compare& comp, const Allocator& alloc );
          template< class InputIter, class Allocator >

          flat_multiset( std::sorted_equivalent_t s, InputIter first,
       (22) (since C++23)
          InputIter last,

                         const Allocator& alloc );
          flat_multiset( std::initializer_list<value_type> init,

                         const key_compare& comp = key_compare() )
       (23) (since C++23)

              : flat_multiset(init.begin(), init.end(), comp) { }
          template< class Allocator >

          flat_multiset( std::initializer_list<value_type> init, const
       (24) (since C++23)
          key_compare& comp,

                         const Allocator& alloc );
          template< class Allocator >
          flat_multiset( std::initializer_list<value_type> init, const
       (25) (since C++23)
          Allocator& alloc );
          flat_multiset( std::sorted_equivalent_t s,
          std::initializer_list<value_type> init,
                                                                            (26)
       (since C++23)
                         const key_compare& comp = key_compare() )

              : flat_multiset(s, init.begin(), init.end(), comp) { }
          template< class Allocator >

          flat_multiset( std::sorted_equivalent_t s,
       (27) (since C++23)
          std::initializer_list<value_type> init,

                         const key_compare& comp, const Allocator& alloc );
          template< class Allocator >

          flat_multiset( std::sorted_equivalent_t s,
       (28) (since C++23)
          std::initializer_list<value_type> init,

                         const Allocator& alloc );

okay so thatโ€™s the whole roster. now letโ€™s actually talk about what each one does, bestie.

๐Ÿ’– Description ๐Ÿ’–

Constructs a new container adaptor from a variety of data sources and optionally provided comparison function object comp and/or allocator alloc. lowkey a constructor buffet. letโ€™s go one by one.

  1. (1) a default constructor. constructs an empty container adaptor. clean, simple, no notes.
  2. (2) a copy constructor. constructs c with the copy of the contents of other.c and compare with other.compare. see allocator usage note below.
  3. (3) a move constructor. constructs the container adaptor with the contents of other using move semantics. see allocator usage note below.
  4. (4) constructs the underlying container with the contents of the container cont. first, initializes c with std::move(cont) and compare with comp. then sorts the c with respect to comp. okay so it moves, then sorts. got it.
  5. (5) same as (4), equivalent to flat_multiset(cont);. see allocator usage note below.
  6. (6) same as (4), equivalent to flat_multiset(cont, comp);. see allocator usage note below.
  7. (7) constructs the underlying container with the contents of the other container cont. initializes c with std::move(cont) and compare with comp. this is the sorted-equivalent-tag one, so itโ€™s already promising the input sequence is sorted. fancy.
  8. (8) same as (7), equivalent to flat_multiset(s, cont);. see allocator usage note below.
  9. (9) same as (7), equivalent to flat_multiset(s, cont, comp);. see allocator usage note below.
  10. (10) constructs an empty container adaptor. the explicit comp one. it literally initializes : c(), compare(comp) { }. empty but opinionated.
  11. (11), (12) constructs an empty container adaptor. see allocator usage note below.
  12. (13) constructs the container adaptor with the contents of the range [first, last), equivalent to insert(first, last);.
  13. (14), (15) same as (13). see allocator usage note below.
  14. (16) constructs the container adaptor with the contents of the range rg. first, uses (10) as delegating constructor. then initializes c with the contents of rg as if by insert_range(std::forward<R>(rg));.
  15. (17) same as (16) using it as delegating constructor. yes, fr is the tag, rg is the range, itโ€™s all happening.
  16. (18), (19) same as (16). see allocator usage note below.
  17. (20) constructs the underlying container with the contents of the range [first, last). initializes c with c(first, last) and compare with compare(comp). thatโ€™s the sorted-tag + iterator-range combo, bestie.
  18. (21), (22) same as (20). see allocator usage note below.
  19. (23) an initializer-list constructor. constructs the underlying container with the contents of the initializer list init, using (13) as delegating constructor.
  20. (24), (25) same as (23). see allocator usage note below.
  21. (26) an initializer-list constructor. constructs the underlying container with the contents of the initializer list init, using (20) as delegating constructor.
  22. (27), (28) Save as (26). see allocator usage note below. (yes, โ€œSave asโ€, thatโ€™s what the page says, weโ€™re not editing the sacred text.)
โš ๏ธ note for overloads (13-15,20-22): if [first, last) is not a valid range, the behavior is undefined. like, undefined undefined. do not play with that range unless you mean it.

๐ŸŒธ Parameters ๐ŸŒธ

  • cont โ€” a container to be used as source to initialize the underlying container.
  • other โ€” another flat_multiset 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 โ€” a range to copy the elements from.
  • init โ€” an initializer list to initialize the elements of the underlying container with.
  • rg โ€” a container compatible range (that is, an input_range whose elements are convertible to value_type) to be used as source to initialize the underlying container.
  • fr โ€” a disambiguation tag that indicates that the contained member should be range constructed.
  • s โ€” a disambiguation tag that indicates that the input sequence is sorted with respect to compare.

๐Ÿฆ‹ Type requirements ๐Ÿฆ‹

  • InputIt must meet the requirements of LegacyInputIterator.
  • Compare must meet the requirements of Compare.
  • Allocator must meet the requirements of Allocator.

๐Ÿฆ‹ COMPLEXITY ๐Ÿฆ‹

okay bestie, hereโ€™s the timing tea โ˜• โ€” every numbered vibe below is straight from the source, no cap:

  • 1) Constant. literally no drama.
  • 2) Linear in size of other.
  • 3) Same as the corresponding move-constructor of the wrapped container, i.e. constant or linear in size of cont.
  • 4-6) Linear in \(\scriptsize N\)N if cont is sorted with respect to compare, otherwise \(\scriptsize \mathcal{O}(N\cdot\log{(N)})\)๐“ž(Nยทlog(N)), where \(\scriptsize N\)N is the value of cont.size() before this call.
  • 7-9) Same as the corresponding move-constructor of the wrapped container, i.e. constant or linear in size of cont.
  • 10-12) Constant.
  • 13-15) Linear in \(\scriptsize N\)N if the input range [first, last) is sorted with respect to compare, otherwise \(\scriptsize \mathcal{O}(N\cdot\log{(N)})\)๐“ž(Nยทlog(N)), where \(\scriptsize N\)N is the value of cont.size() before this call.
  • 16-19) Linear in \(\scriptsize N\)N if the input range rg is sorted with respect to compare, otherwise \(\scriptsize \mathcal{O}(N\cdot\log{(N)})\)๐“ž(Nยทlog(N)), where \(\scriptsize N\)N is the value of cont.size() before this call.
  • 20-22) Linear in size of [first, last).
  • 23-25) Linear in \(\scriptsize N\)N if the elements of init are sorted with respect to compare, otherwise \(\scriptsize \mathcal{O}(N\cdot\log{(N)})\)๐“ž(Nยทlog(N)), where \(\scriptsize N\)N is the value of cont.size() before this call.
  • 26-28) Linear in size of init.

๐Ÿ˜ญ EXCEPTIONS ๐Ÿ˜ญ

Calls to Allocator::allocate may throw. so yeah, allocation can absolutely throw hands โ€” keep that in mind ๐Ÿซถ


๐Ÿ“ 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.

bestie this is the โ€œyour stuff survived the move but it lives in a new address nowโ€ situation ๐Ÿ’…

๐ŸŒธ EXAMPLE ๐ŸŒธ

This section is incomplete

Reason: no example

sorry bestie, sheโ€™s giving โ€œempty group chatโ€ energy โ€” no example here ๐Ÿ˜ญ


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

  • operator= โ€” assigns values to the container adaptor (public member function)

Category:

  • Todo no example

okay thatโ€™s the whole vibe check ๐Ÿ’– signing off with source/version cppreference.com and date 2024.06.10, for the page std::flat_m...lat_multiset(3) โ€” slay, bye bestie ๐ŸŽ€โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from