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@lists.isocpp.org> On Behalf Of Simon W via Std-Proposals
Sent: Wednesday, May 21, 2025 10:12 AM
To: std-proposals@lists.isocpp.org
Cc: Simon W <inte2012@gmail.com>
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;