Date: Sat, 10 Jan 2026 14:27:37 +0000
assume a situation in P2688R5:
variant<variant<int>> v;
v match {
auto: auto: let integer => intger
//the two "auto"s refers to distinct types, but lexically it likes that they belong to the same object
}
If treating alternative as subobject, the nesting relationship is straightforward.
v match {
[[let interger]] => integer
}
Also, accroding to the standard, "A variant object holds and manages the lifetime of a value". So the pattern matching syntax is better to reflect the nesting relationship.
________________________________
发件人: Jens Maurer <jens.maurer_at_[hidden]>
已发送: 2026 年 1 月 10 日 星期六 21:31
收件人: std-proposals_at_[hidden] <std-proposals_at_[hidden]>
抄送: 徐 一凡 <xuyifan2004_at_outlook.com>
主题: Re: [std-proposals] treat alternative as subobject when pattern-matching variant-like types
Could you please offer a complete code example, with struct definitions etc.
as needed to show your point?
Jens
On 1/10/26 14:19, 徐 一凡 via Std-Proposals wrote:
> In P2688R5 pattern matching, variant-like and polymorphic types share the similar syntax to match alternatives or subtypes. This syntax is confusing for implying the type of alternatives to be a subtype. Also, this syntax makes it awkward to distinguish between the variant-like itself and its alternatives.
>
> In P2688R5, 'auto: let' is introduced to distinguish from 'let':
> auto: let alternative => //...
> let self => //...
>
> I suggest to treat alternative as subobject, which is far more straightforward:
> [let alternative] => //...
> let self => //...
>
> It can also be applied to pointer-like types such as optional, free from reusing '?':
> [let some] => //...
> nullptr => //...
> nullopt => //...
>
> The reason for the new syntax is that an alternative or a pointed-to is a distinct object beneath the matched object, rather than just a different interpretation of the same object. The old syntax should be only applied to type matching which can be performed through built-in casts.
>
variant<variant<int>> v;
v match {
auto: auto: let integer => intger
//the two "auto"s refers to distinct types, but lexically it likes that they belong to the same object
}
If treating alternative as subobject, the nesting relationship is straightforward.
v match {
[[let interger]] => integer
}
Also, accroding to the standard, "A variant object holds and manages the lifetime of a value". So the pattern matching syntax is better to reflect the nesting relationship.
________________________________
发件人: Jens Maurer <jens.maurer_at_[hidden]>
已发送: 2026 年 1 月 10 日 星期六 21:31
收件人: std-proposals_at_[hidden] <std-proposals_at_[hidden]>
抄送: 徐 一凡 <xuyifan2004_at_outlook.com>
主题: Re: [std-proposals] treat alternative as subobject when pattern-matching variant-like types
Could you please offer a complete code example, with struct definitions etc.
as needed to show your point?
Jens
On 1/10/26 14:19, 徐 一凡 via Std-Proposals wrote:
> In P2688R5 pattern matching, variant-like and polymorphic types share the similar syntax to match alternatives or subtypes. This syntax is confusing for implying the type of alternatives to be a subtype. Also, this syntax makes it awkward to distinguish between the variant-like itself and its alternatives.
>
> In P2688R5, 'auto: let' is introduced to distinguish from 'let':
> auto: let alternative => //...
> let self => //...
>
> I suggest to treat alternative as subobject, which is far more straightforward:
> [let alternative] => //...
> let self => //...
>
> It can also be applied to pointer-like types such as optional, free from reusing '?':
> [let some] => //...
> nullptr => //...
> nullopt => //...
>
> The reason for the new syntax is that an alternative or a pointed-to is a distinct object beneath the matched object, rather than just a different interpretation of the same object. The old syntax should be only applied to type matching which can be performed through built-in casts.
>
Received on 2026-01-10 14:27:43
