Date: Fri, 15 Nov 2024 08:46:46 +1100
On 15/11/24 00:33, Bo Persson via Std-Discussion wrote:
> On 2024-11-14 at 14:22, Russell Shaw via Std-Discussion wrote:
>> On 14/11/24 22:47, Ville Voutilainen wrote:
>>> On Thu, 14 Nov 2024 at 13:09, Russell Shaw via Std-Discussion
>>> <std-discussion_at_[hidden]> wrote:
>>>
>>>> So "struct S { static const int x = 0; };" 'defines' 'S::x' because it has an
>>>> initializer, yet has no memory location ?
>>>
>>> Right, it has no memory location, but the value is known, and known
>>> not to change, so anything
>>> that just uses the value but doesn't need the address can simply be
>>> replaced by that value.
>>
>> Later, it says:
>>
>> "A structured binding is odr-used if it appears as a potentially- evaluated
>> expression."
>>
>> --------------------------
>> int a[1];
>>
>> auto [x] = a; <---- (A)
>> --------------------------
>>
>> Is (A) the "structured binding" and "potentially-evaluated expression." ? Or a
>> declaration ?
>>
>> Or is 'x' the "structured binding" ?
>
> This is way out in the corner, but x works like a reference (similar to the
> parameter in the earlier example).
>
> If you use x, that reference must be valid, but if you just declare it and never
> use it (Why would you?), apparently you get away with the "reference" not really
> working.
>
> I wouldn't bother too much with getting the exact details. :-)
Hi, i should have read further. 'x' is the structured binding.
-------------------------------------
9.6 Structured binding declarations [dcl.struct.bind]
A structured binding declaration introduces the identifier s v0, v1, v2 , . . .
of the identifier-list as names of structured bindings.
-------------------------------------
I was very rusty since reading the standard last time. Trying to understand all
the details this time.
int main()
{
int a[1]{3};
auto [x] = a; // a[0]=3, x=3 ('x' an ordinary int variable)
a[0] = 4; // a[0]=4, x=3
x = 5; // a[0]=4, x=5
}
int main()
{
int a[1]{3};
auto & [x] = a; // a[0]=3, x=3 ('x' a reference to an int)
a[0] = 4; // a[0]=4, x=4
x = 5; // a[0]=5, x=5
}
> On 2024-11-14 at 14:22, Russell Shaw via Std-Discussion wrote:
>> On 14/11/24 22:47, Ville Voutilainen wrote:
>>> On Thu, 14 Nov 2024 at 13:09, Russell Shaw via Std-Discussion
>>> <std-discussion_at_[hidden]> wrote:
>>>
>>>> So "struct S { static const int x = 0; };" 'defines' 'S::x' because it has an
>>>> initializer, yet has no memory location ?
>>>
>>> Right, it has no memory location, but the value is known, and known
>>> not to change, so anything
>>> that just uses the value but doesn't need the address can simply be
>>> replaced by that value.
>>
>> Later, it says:
>>
>> "A structured binding is odr-used if it appears as a potentially- evaluated
>> expression."
>>
>> --------------------------
>> int a[1];
>>
>> auto [x] = a; <---- (A)
>> --------------------------
>>
>> Is (A) the "structured binding" and "potentially-evaluated expression." ? Or a
>> declaration ?
>>
>> Or is 'x' the "structured binding" ?
>
> This is way out in the corner, but x works like a reference (similar to the
> parameter in the earlier example).
>
> If you use x, that reference must be valid, but if you just declare it and never
> use it (Why would you?), apparently you get away with the "reference" not really
> working.
>
> I wouldn't bother too much with getting the exact details. :-)
Hi, i should have read further. 'x' is the structured binding.
-------------------------------------
9.6 Structured binding declarations [dcl.struct.bind]
A structured binding declaration introduces the identifier s v0, v1, v2 , . . .
of the identifier-list as names of structured bindings.
-------------------------------------
I was very rusty since reading the standard last time. Trying to understand all
the details this time.
int main()
{
int a[1]{3};
auto [x] = a; // a[0]=3, x=3 ('x' an ordinary int variable)
a[0] = 4; // a[0]=4, x=3
x = 5; // a[0]=4, x=5
}
int main()
{
int a[1]{3};
auto & [x] = a; // a[0]=3, x=3 ('x' a reference to an int)
a[0] = 4; // a[0]=4, x=4
x = 5; // a[0]=5, x=5
}
Received on 2024-11-14 21:46:52