C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Fwd: Extension to runtime polymorphism proposed

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sat, 11 Apr 2026 09:50:49 -0600
On Saturday, 11 April 2026 06:22:43 Mountain Daylight Time Muneem via Std-
Proposals wrote:
> Just to make sure that we are on the same page:
> we both agree that "std::optional<int&> x = list[index];"
> 1. std::optional<int&> 's constructor should throw an exception if the
> variant returned by list[index] is not an int.

No, it just constructs a disengaged std::optional. It's on use that the user
decide on throwing or adding a fallback path.

You can get the "throw-on-creation" you're describing by *using* the optional
immediately without a fallback.

> 2. For std::variant<T&...> to work, we need support from the implementation

Yes, of course.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.

Received on 2026-04-11 15:50:56