std::forward_list<T,Allocator>:: forward_list
|
forward_list
(
)
:
forward_list
(
Allocator
(
)
)
{
}
|
(1) | (constexpr depuis C++26) |
|
explicit
forward_list
(
const
Allocator
&
alloc
)
;
|
(2) | (constexpr depuis C++26) |
|
explicit
forward_list
(
size_type count,
const Allocator & alloc = Allocator ( ) ) ; |
(3) | (constexpr depuis C++26) |
|
forward_list
(
size_type count,
const
T
&
value,
const Allocator & alloc = Allocator ( ) ) ; |
(4) | (constexpr depuis C++26) |
|
template
<
class
InputIt
>
forward_list
(
InputIt first, InputIt last,
|
(5) | (constexpr depuis C++26) |
|
template
<
container-compatible-range
<
T
>
R
>
forward_list
(
std::
from_range_t
, R
&&
rg,
|
(6) |
(depuis C++23)
(constexpr depuis C++26) |
|
forward_list
(
const
forward_list
&
other
)
;
|
(7) | (constexpr depuis C++26) |
|
forward_list
(
forward_list
&&
other
)
;
|
(8) | (constexpr depuis C++26) |
| (9) | ||
|
forward_list
(
const
forward_list
&
other,
const
Allocator
&
alloc
)
;
|
(jusqu'en C++23) | |
|
forward_list
(
const
forward_list
&
other,
const std:: type_identity_t < Allocator > & alloc ) ; |
(depuis C++23)
(constexpr depuis C++26) |
|
| (10) | ||
|
forward_list
(
forward_list
&&
other,
const
Allocator
&
alloc
)
;
|
(jusqu'au C++23) | |
|
forward_list
(
forward_list
&&
other,
const std:: type_identity_t < Allocator > & alloc ) ; |
(depuis C++23)
(constexpr depuis C++26) |
|
|
forward_list
(
std::
initializer_list
<
T
>
init,
const Allocator & alloc = Allocator ( ) ) ; |
(11) | (constexpr depuis C++26) |
Construit un nouveau
forward_list
à partir de diverses sources de données, en utilisant optionnellement un allocateur fourni par l'utilisateur
alloc
.
forward_list
vide avec un allocateur construit par défaut.
forward_list
vide avec l'allocateur donné
alloc
.
forward_list
avec
count
objets par défaut de
T
. Aucune copie n'est effectuée.
forward_list
avec
count
copies d'éléments de valeur
value
.
forward_list
avec le contenu de la plage
[
first
,
last
)
. Chaque itérateur dans
[
first
,
last
)
est déréférencé exactement une fois.
InputIt
satisfait aux exigences de
LegacyInputIterator
.
T
n'est pas
EmplaceConstructible
dans
forward_list
à partir de
*
first
, le comportement est indéfini.
forward_list
avec le contenu de la plage
rg
. Chaque itérateur dans
rg
est déréférencé exactement une fois.
T
n'est pas
EmplaceConstructible
dans
forward_list
à partir de
*
ranges::
begin
(
rg
)
, le comportement est indéfini.
forward_list
avec le contenu de
other
. L'allocateur est obtenu comme si en appelant
std::
allocator_traits
<
Allocator
>
::
select_on_container_copy_construction
( other. get_allocator ( ) ) .
forward_list
avec le contenu de
other
. L'allocateur est obtenu par construction par déplacement depuis
other.
get_allocator
(
)
.
SommaireParamètres
Complexité
1,2)
Constant.
3,4)
Linéaire en
count
.
5)
Linéaire en
std::
distance
(
first, last
)
.
6)
Linéaire en
ranges::
distance
(
rg
)
.
7)
Linéaire en
other.
size
(
)
.
8)
Constante.
9)
Linéaire en
other.
size
(
)
.
10)
Linéaire en
other.
size
(
)
si
alloc
!
=
other.
get_allocator
(
)
, sinon constant.
11)
Linéaire en
init.
size
(
)
.
ExceptionsLes appels à Allocator :: allocate peuvent lever des exceptions. NotesAprès la construction par déplacement d'un conteneur (surcharge (8)), les références, pointeurs et itérateurs qui se référaient initialement aux éléments dans
Exemple
Exécuter ce code
#include <forward_list> #include <iostream> #include <string> template<typename T> std::ostream& operator<<(std::ostream& s, const std::forward_list<T>& v) { s.put('{'); for (char comma[]{'\0', ' ', '\0'}; const auto& e : v) s << comma << e, comma[0] = ','; return s << "}\n"; } int main() { // Syntaxe de liste d'initialisation C++11 : std::forward_list<std::string> words1{"the", "frogurt", "is", "also", "cursed"}; std::cout << "1: " << words1; // words2 == words1 std::forward_list<std::string> words2(words1.begin(), words1.end()); std::cout << "2: " << words2; // words3 == words1 std::forward_list<std::string> words3(words1); std::cout << "3: " << words3; // words4 est {"Mo", "Mo", "Mo", "Mo", "Mo"} std::forward_list<std::string> words4(5, "Mo"); std::cout << "4: " << words4; const auto rg = {"cat", "cow", "crow"}; #ifdef __cpp_lib_containers_ranges std::forward_list<std::string> words5(std::from_range, rg); // surcharge (6) #else std::forward_list<std::string> words5(rg.begin(), rg.end()); // surcharge (5) #endif std::cout << "5: " << words5; } Sortie : 1: {the, frogurt, is, also, cursed}
2: {the, frogurt, is, also, cursed}
3: {the, frogurt, is, also, cursed}
4: {Mo, Mo, Mo, Mo, Mo}
5: {cat, cow, crow}
Rapports de défautsLes rapports de défauts modifiant le comportement suivants ont été appliqués rétroactivement aux normes C++ précédemment publiées.
Voir aussi
|