Live data from Hacker News

C++26: Std:Is_within_lifetime

sandordargo.com

1–10 of 75 posts

Re: C++26: Std:Is_within_lifetime

#3
Is this the first type of sum-type option choosing statement present for C++ unions? I've been waiting for this feature since the year 1978.

Still, it's a wasted opportunity not to have a language-level overload to the `switch` statement that allows nice pattern matching. Even with std::is_within_lifetime C++ unions are prone to errors and hard to work with.

Re: C++26: Std:Is_within_lifetime

#4
The problem pointed out in the article seems a little silly. We're adding an entire language feature because someone wanted an optional bool class? Why not just create a uint8_t with three values: OPTIONAL_BOOL_FASLE, OPTIONAL_BOOL_TRUE, OPTIONAL_BOOL_UNDEFINED?

Doing so takes the same space as a bool, and could be wrapped in a class if desired to provide a nicer interface.

Re: C++26: Std:Is_within_lifetime

#8

The problem pointed out in the article seems a little silly. We're adding an entire language feature because someone wanted an optional bool class? Why not just create a uint8_t with three values: OPTIONAL_BOOL_FASLE, OPTIONAL_BOOL_TRUE, OPTIONAL_BOOL_UNDEFINED? Doing so takes the same space as a bool, and could be wrapped in a class if desired to provide a nicer interface.

Exactly my thought. Or a typed enum: enum class uint8_t { NAH, YEAH, OMGWTF };

I'm (fairly) sure there's a good reason for that language feature, but the justification the blog article gives is super weak.

Re: C++26: Std:Is_within_lifetime

#9
post #3

Is this the first type of sum-type option choosing statement present for C++ unions? I've been waiting for this feature since the year 1978. Still, it's a wasted opportunity not to have a language-level overload to the `switch` statement that allows nice pattern matching. Even with std::is_within_lifetime C++ unions are prone to errors and hard to work with.

Since C++17 there is std::variant

https://en.cppreference.com/w/cpp/utility/variant.html

Re: C++26: Std:Is_within_lifetime

#10
Mature lanagues like CPP should stop adding more features to the language/std. Adding features to the language just makes it more complex, and adding to the std library just adds more overhead, and maybe even security issues.
Post reply on HN