Menu

📰
0

Reddit - Please wait for verification

C++·/u/jk-jeon·2 days ago
#zv88fpWG
Reading 0:00
15s threshold

Hi, I observe more and more types with "reference-like" semantics are being added to the standard. Starting from string_view (and our old friends bitset::reference and vector ::reference), we've got optional and function_ref. span and mdspan are also to an extent a reference-like type, though it can be argued that they are more of pointer-like types. I've long hated these reference-like, or so-called "proxy" types because they are all broken, in the sense that they behave very differently from the native references. The language simply disallows a "proper" reference-like type to be written. There are two reasons I know of why this is impossible (there are maybe more): Native references get lifetime-extended, but never with proxies. It is impossible to make a proxy type to behave in the same way as the native references in the context of type deduction. There are certain situations where these result in inconvenience and/or lifetime bugs.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More