Deduktionshilfen für std::forward_list
| Definiert in Header <forward_list> |
||
| template< class InputIt, class Alloc = std::allocator< |
(1) | (seit C++17) |
| template< ranges::input_range R, class Alloc = std::allocator<ranges::range_value_t<R>> > |
(2) | (seit C++23) |
InputIt LegacyInputIterator erfüllt und Alloc Allocator erfüllt.input_range zu ermöglichen.Hinweis: Inwieweit die Bibliothek feststellt, dass ein Typ LegacyInputIterator nicht erfüllt, ist nicht spezifiziert, außer dass ganzzahlige Typen als minimale Eingabeiteratoren nicht in Frage kommen. Ebenso ist nicht spezifiziert, inwieweit die Bibliothek feststellt, dass ein Typ Allocator nicht erfüllt, außer dass als Minimum der Mitgliedstyp Alloc::value_type existieren muss und der Ausdruck std::declval<Alloc&>().allocate(std::size_t{}) gut gebildet ist, wenn er als nicht ausgewerteter Operand behandelt wird.
[bearbeiten] Anmerkungen
| Feature-Test-Makro | Wert | Std | Feature |
|---|---|---|---|
__cpp_lib_containers_ranges |
202202L |
(C++23) | Bereichsbezogene Konstruktion und Einfügung; Überladung (2) |
[bearbeiten] Beispiel
#include <forward_list> #include <vector> int main() { std::vector<int> v = {1, 2, 3, 4}; // uses explicit deduction guide to deduce std::forward_list<int> std::forward_list x(v.begin(), v.end()); // deduces std::forward_list<std::vector<int>::iterator> // first phase of overload resolution for list-initialization selects the candidate // synthesized from the initializer-list constructor; second phase is not performed // and deduction guide has no effect std::forward_list y{v.begin(), v.end()}; }