4 ms·
I’ve never used std::reference_wrapper in my life. Nor have I seen it used in any of the numerous C++ code bases I’ve worked in. Although I’m sure it’s used in
by forrestthewoods 2y ago
I’ve never used std::reference_wrapper in my life. Nor have I seen it used in any of the numerous C++ code bases I’ve worked in. Although I’m sure it’s used in deep, gnarly template BS.
Your statement may be correct! But it’s certainly not common knowledge in my experience.
- shrimp_emoji 2y agoI use them now and then -- and I never touch templates. It's just a reference you can reassign. Or, in other words, truly a pointer that can't be null. :D (And that you can actually use in collections that require reassignable types.)
- nickysielicki 2y agoMy stance is just based on cpp core guidelines: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-constref https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines... https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-zero https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines... std::reference_wrapper still can’t save you from yourself, but it’s better than violating the first link and ending up in this limbo that OP is talking about. See also: https://youtu.be/YxSg_Gzm-VQ https://youtu.be/YxSg_Gzm-VQ (about 3:30 in)
- lenkite 2y agoThat link says nothing about std::reference_wrapper ?
- nickysielicki 2y agoI’m just saying, nothing up my sleeve, no arcane templatelord bullshit, this is isocpp: don’t use references in your structs because it’s subtly broken. It doesn’t mention reference wrappers but that’s the escape hatch.
- Guvante 2y agoIf you want to use assignment operators with references that is what it does. Nothing else.