1. ...If the assignment-expression in the initializer has array type A and no
ref-qualifier is present, e has type cv A and each element is copy-initialized or direct-initialized from the
corresponding element of the assignment-expression as specified by the form of the initializer. ...
corresponding element of the assignment-expression as specified by the form of the initializer. ...
const int a[] = { 10, 20 };
auto [first, second] = a;
2 If E is an array type with element type T, the number of elements in the identifier-list shall be equal to
the number of elements of E. Each vi is the name of an lvalue that refers to the element i of the array
and whose type is T; the referenced type is T.the number of elements of E. Each vi is the name of an lvalue that refers to the element i of the array and whose type is T; the referenced type is T. and whose type is T; the referenced type is T.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
On 4 Jun 2018, at 11:40, 'Vlad from Moscow' via ISO C++ Standard - Discussion <std-dis...@isocpp.org> wrote:In the paragraph #1 of the section "11.5 Structured binding declarations" there is written1. ...If the assignment-expression in the initializer has array type A and no
ref-qualifier is present, e has type cv A and each element is copy-initialized or direct-initialized from the
corresponding element of the assignment-expression as specified by the form of the initializer. ...
corresponding element of the assignment-expression as specified by the form of the initializer. ...So let's consider the following declarations
const int a[] = { 10, 20 };
auto [first, second] = a;The type of the identifier a is const int[2]. Thus the variable with the unique name e also should have the type const int[2].So according to the paragraph #2 of the section2 If E is an array type with element type T, the number of elements in the identifier-list shall be equal to
the number of elements of E. Each vi is the name of an lvalue that refers to the element i of the array
and whose type is T; the referenced type is T.the number of elements of E. Each vi is the name of an lvalue that refers to the element i of the array and whose type is T; the referenced type is T. and whose type is T; the referenced type is T.the names first and second should have the type const int because the element type of the array e is const int.However the actual type of the names is int according to the gcc compiler.Either I missed something or the description of the section requires some editions.The way I read this was “e has type cv A”, the cv coming from the declaration of auto[…].
--
#include <iostream>
int main()
{
const int a[] = { 10, 20 };
auto [first, second] = a;
std::cout << first << ", " << second << std::endl;
first = 1;
std::cout << first << ", " << second << std::endl;
}
No I agree. The type should be const int, and not int. Indeed, on clang, the types are const int.I don't think it's worth changing the wording, I find it clear enough.
--
Hmm I see your point. I guess it's for consistency:const int* a = nullptr;auto b = a;Now b is const int*. If we imagine a [] instead of a *, then it would also make sense for the individual elements to be const too. Of course that syntax is imaginary, but I can see why this is the case.
Hmmauto x = <anything>;results in a mutable, non-volatile copy of the <anything>. Even if the <anything> is a pointer to a const thing. Remember that the pointer itself is a discrete object.
butauto [x] = <the same thing>;sometimes results in a mutable non-volatile copy? I can't imagine any scenario in which this makes sense.
I'll wager you a beer that it's an oversight in the wording.
--