Namensräume
Varianten
Aktionen

std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::flat_map

Von cppreference.com
< cpp‎ | container‎ | flat map
 
 
 
 
flat_map()
    : flat_map(key_compare()) { }
(1) (seit C++23)
template< class Allocator >
flat_map( const flat_map&, const Allocator& alloc );
(2) (seit C++23)
template< class Allocator >
flat_map( flat_map&&, const Allocator& alloc );
(3) (seit C++23)
flat_map( key_container_type key_cont, mapped_container_type mapped_cont,
          const key_compare& comp = key_compare() );
(4) (seit C++23)
template< class Allocator >

flat_map( const key_container_type& key_cont,
          const mapped_container_type& mapped_cont,

          const Allocator& alloc );
(5) (seit C++23)
template< class Allocator >

flat_map( const key_container_type& key_cont,
          const mapped_container_type& mapped_cont,

          const key_compare& comp, const Allocator& alloc );
(6) (seit C++23)
flat_map( std::sorted_unique_t, key_container_type key_cont,

         mapped_container_type mapped_cont,

          const key_compare& comp = key_compare() );
(7) (seit C++23)
template< class Allocator >

flat_map( std::sorted_unique_t, const key_container_type& key_cont,

          const mapped_container_type& mapped_cont, const Allocator& alloc );
(8) (seit C++23)
template< class Allocator >

flat_map( std::sorted_unique_t, const key_container_type& key_cont,
          const mapped_container_type& mapped_cont,

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

flat_map( InputIter first, InputIter last,
          const key_compare& comp = key_compare() )

    : c(), compare(comp);
(13) (seit C++23)
template< class InputIter, class Allocator >

flat_map( InputIter first, InputIter last,

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

flat_map( std::from_range_t, R&& rg, const key_compare& comp )

    : flat_map(comp);
(16) (seit C++23)
template< container-compatible-range<value_type> R >

flat_map( std::from_range_t fr, R&& rg )

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

flat_map( std::from_range_t, R&& rg, const key_compare& comp,

          const Allocator& alloc );
(19) (seit C++23)
template< class InputIter >

flat_map( std::sorted_unique_t s, InputIter first, InputIter last,
          const key_compare& comp = key_compare() )

    : c(), compare(comp);
(20) (seit C++23)
template< class InputIter, class Allocator >

flat_map( std::sorted_unique_t s, InputIter first, InputIter last,

          const key_compare& comp, const Allocator& alloc );
(21) (seit C++23)
template< class InputIter, class Allocator >

flat_map( std::sorted_unique_t s, InputIter first, InputIter last,

          const Allocator& alloc );
(22) (seit C++23)
flat_map( std::initializer_list<value_type> init,

          const key_compare& comp = key_compare() )

    : flat_map(init.begin(), init.end(), comp) { }
(23) (seit C++23)
template< class Allocator >

flat_map( std::initializer_list<value_type> init, const key_compare& comp,

          const Allocator& alloc );
(24) (seit C++23)
template< class Allocator >
flat_map( std::initializer_list<value_type> init, const Allocator& alloc );
(25) (seit C++23)
flat_map( std::sorted_unique_t s, std::initializer_list<value_type> init,

          const key_compare& comp = key_compare() )

    : flat_map(s, init.begin(), init.end(), comp) { }
(26) (seit C++23)
template< class Allocator >

flat_map( std::sorted_unique_t s, std::initializer_list<value_type> init,

          const key_compare& comp, const Allocator& alloc );
(27) (seit C++23)
template< class Allocator >

flat_map( std::sorted_unique_t s, std::initializer_list<value_type> init,

          const Allocator& alloc );
(28) (seit C++23)

Konstruiert einen neuen Container-Adapter aus verschiedenen Datenquellen, optional unter Verwendung eines vom Benutzer bereitgestellten Vergleichsobjekts comp und/oder Allocators alloc.

1) Ein Standardkonstruktor. Konstruiert einen leeren Container-Adapter.
2) Ein Kopierkonstruktor. Konstruiert c mit einer Kopie des Inhalts von other.c und compare mit other.compare. Siehe Hinweis zur Allocator-Nutzung unten.
3) Ein Verschiebekonstruktor. Konstruiert den Container-Adapter mit dem Inhalt von other unter Verwendung der Verschiebungssemantik. Siehe Allocator-Nutzungshinweis unten.
4) Zuerst werden c.keys mit std::move(key_cont), c.values mit std::move(mapped_cont) und compare mit comp initialisiert. Dann wird der zugrundeliegende Bereich [begin()end()) bezüglich value_comp() sortiert. Schließlich werden doppelte Elemente gelöscht, als ob durch:
auto zv = views::zip(c.keys, c.values);
auto it = ranges::unique(zv, key_equiv(compare)).begin();
auto dist = distance(zv.begin(), it);
c.keys.erase(c.keys.begin() + dist, c.keys.end());
c.values.erase(c.values.begin() + dist, c.values.end());
.
5) Wie (4), äquivalent zu flat_map(key_cont, mapped_cont);. Siehe Hinweis zur Allocator-Nutzung unten.
6) Wie (4), äquivalent zu flat_map(key_cont, mapped_cont, comp);. Siehe Hinweis zur Allocator-Nutzung unten.
7) Initialisiert c.keys mit std::move(key_cont), c.values mit std::move(mapped_cont) und compare mit comp.
8) Wie (7), äquivalent zu flat_map(s, key_cont, mapped_cont);. Siehe Hinweis zur Allocator-Nutzung unten.
9) Wie (7), äquivalent zu flat_map(s, key_cont, mapped_cont, comp);. Siehe Hinweis zur Allocator-Nutzung unten.
10) Konstruiert einen leeren Container-Adapter.
11,12) Konstruiert einen leeren Container-Adapter. Siehe Allocator-Nutzungshinweis unten.
13) Konstruiert den Container-Adapter mit dem Inhalt des Bereichs [firstlast), äquivalent zu insert(first, last);.
14,15) Ähnlich wie (13). Siehe Allocator-Nutzungshinweis unten.
16) Konstruiert den Container-Adapter mit dem Inhalt des Bereichs rg. Zuerst wird (10) als delegierender Konstruktor verwendet. Dann wird c mit dem Inhalt von rg initialisiert, als ob durch insert_range(std::forward<R>(rg));.
17) Ähnlich wie (16), unter Verwendung als delegierender Konstruktor.
18,19) Ähnlich wie (16). Siehe Allocator-Nutzungshinweis unten.
20) Die zugrundeliegenden Container werden mit dem Inhalt des Bereichs [firstlast) wie durch insert(first, last) initialisiert.
21,22) Ähnlich wie (20). Siehe Allocator-Nutzungshinweis unten.
23) Ein Konstruktor für Initialisierungslisten. Konstruiert den zugrunde liegenden Container mit dem Inhalt der Initialisierungsliste init, unter Verwendung von (13) als delegierender Konstruktor.
24,25) Ähnlich wie (23). Siehe Allocator-Nutzungshinweis unten.
26) Ein Konstruktor für Initialisierungslisten. Konstruiert den zugrunde liegenden Container mit dem Inhalt der Initialisierungsliste init, unter Verwendung von (20) als delegierender Konstruktor.
27,28) Ähnlich wie (26). Siehe Allocator-Nutzungshinweis unten.

Hinweis zu Überladungen (13-15,20-22): Wenn [firstlast) kein gültiger Bereich ist, ist das Verhalten undefiniert.

Hinweis zu Überladungen (4-6,13-19,23-25): Wenn mehrere Elemente im Bereich Schlüssel haben, die äquivalent sind, ist es nicht spezifiziert, welches Element eingefügt wird (vorbehaltlich LWG2844).

Inhalt

[bearbeiten] Hinweis zur Allocator-Nutzung

Die Konstruktoren (2,3,5,6,8,9,11,12,14,15,17,19,21,22,24,25,27,28) sind äquivalent zu den entsprechenden Konstruktoren ohne Allocator, außer dass die zugrundeliegenden Container c.keys und c.values mit uses-allocator-Konstruktion konstruiert werden. Diese Überladungen nehmen nur an der Auflösung von Überladungen teil, wenn std::uses_allocator_v<container_type, Allocator> true ist.

[bearbeiten] Parameter

key_cont - ein Container, der als Quelle zur Initialisierung des zugrundeliegenden Schlüssel-Containers verwendet wird
mapped_cont - ein Container, der als Quelle zur Initialisierung des zugrundeliegenden Werte-Containers verwendet wird
Sonstiges - eine andere flat_map, die als Quelle zur Initialisierung der Elemente der zugrundeliegenden Container verwendet wird
alloc - ein Allocator, der für alle Speicherallokationen der zugrundeliegenden Container verwendet wird
comp - Ein Funktions-Objekt, das für alle Vergleiche von Schlüsseln verwendet wird
first, last - das Iteratorpaar, das den Quell-Bereich der zu kopierenden Elemente definiert
init - eine Initialisierungsliste zur Initialisierung der Elemente der zugrundeliegenden Container
rg - ein Container-kompatibler Bereich (d. h. ein input_range, dessen Elemente in value_type konvertierbar sind) zur Initialisierung der zugrundeliegenden Container
fr - Ein Disambiguierungstag, der angibt, dass das enthaltene Element per Bereich konstruiert werden soll
s - ein Diskriminierungs-Tag, der anzeigt, dass die Eingabesequenz bezüglich value_comp() sortiert ist und alle ihre Elemente eindeutig sind
Typanforderungen
-
InputIt muss die Anforderungen von LegacyInputIterator erfüllen.
-
Compare muss die Anforderungen an Compare erfüllen.
-
Allocator muss die Anforderungen an Allocator erfüllen.

[bearbeiten] Komplexität

1) Konstant.
2) Linear zur Größe von other.
3) Ähnlich wie der entsprechende Verschiebekonstruktor des umschlossenen Containers, d. h. konstant oder linear zur Größe von cont.
4-6) Linear in N, wenn cont bezüglich value_comp() sortiert ist, andernfalls 𝓞(N·log(N)), wobei N der Wert von key_cont.size() vor diesem Aufruf ist.
7-9) Ähnlich wie der entsprechende Verschiebekonstruktor des umschlossenen Containers, d. h. konstant oder linear zur Größe von cont.
10-12) Konstant.
13-15) Linear in N, wenn der Eingabebereich [firstlast) bezüglich value_comp() sortiert ist, andernfalls 𝓞(N·log(N)), wobei N der Wert von key_cont.size() vor diesem Aufruf ist.
16-19) Linear in N, wenn der Eingabebereich rg bezüglich value_comp() sortiert ist, andernfalls 𝓞(N·log(N)), wobei N der Wert von key_cont.size() vor diesem Aufruf ist.
20-22) Linear zur Größe von [firstlast).
23-25) Linear in N, wenn die Elemente von init bezüglich value_comp() sortiert sind, andernfalls 𝓞(N·log(N)), wobei N der Wert von key_cont.size() vor diesem Aufruf ist.
26-28) Linear zur Größe von init.

[bearbeiten] Ausnahmen

Aufrufe von Allocator::allocate können Ausnahmen auslösen.

[bearbeiten] Hinweise

Nach der Verschiebekonstruktion des Containers (Überladung (3)) bleiben Referenzen, Zeiger und Iteratoren (außer dem End-Iterator) von other gültig, verweisen aber auf Elemente, die sich nun in *this befinden. Der aktuelle Standard garantiert dies durch die allgemeine Aussage in [container.reqmts]/67, und eine direktere Garantie wird im Rahmen von LWG-Problem 2321 in Betracht gezogen.

[bearbeiten] Beispiel

[bearbeiten] Siehe auch

weist Werte dem Container-Adapter zu
(public member function) [edit]