C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Hope that std::optional and comma expressions can work this way

From: Tiago Freire <tmiguelf_at_[hidden]>
Date: Thu, 22 May 2025 11:06:13 +0000
If you understand why this is invalid code.

auto foo(bool test)
{
return test ? 42 : std::nullopt;
}

You will understand why this “should” not work.

From: Std-Proposals <std-proposals-bounces_at_[hidden]> On Behalf Of Simon W via Std-Proposals
Sent: Wednesday, May 21, 2025 10:12 AM
To: std-proposals_at_[hidden]
Cc: Simon W <inte2012_at_[hidden]>
Subject: [std-proposals] Hope that std::optional and comma expressions can work this way


The comma expression requires that the expressions on both sides of the colon are of the same type. But I think this syntax should be accepted:

bool AllInUniversial();

std::optional<int> r = AllInUniversial() ? 42 : std::nullopt;

Received on 2025-05-22 11:06:16