The section $11.3 (Lists) is a bit confusing to me.
Quoting the book,
The implementation model for {}-lists comes in three parts:
• If the {}-list is used as constructor arguments, the implementation is just as if you had used a ()-list. List elements are not copied except as by-value constructor arguments.
• If the {}-list is used to initialize the elements of an aggregate (an array or a class without a constructor), each list element initializes an element of the aggregate. List elements are not copied except as by-value arguments to aggregate element constructors.
• If the {}-list is used to construct an initializer_list object each list element is used to initialize an element of the underlying array of the initializer_list. Elements are typically copied from the initializer_list to wherever we use them.
The most popular use of {}-list seems to be initializer_list. In which, a temporary immutable is created, hence it is copy-initialized.
For constructor arguments and an aggregate, the book says the elements are not copied. How are these different than initializer_list?
What exactly does "List elements are not copied except as by-value arguments to aggregate element constructors." mean? It seems contradictory.
Aucun commentaire:
Enregistrer un commentaire