3 ms·
This has been slightly confusing to me, but the syntax auto&& might not mean an rvalue reference. According to the post, it means a universal reference. I wish
by sseagull 10y ago
This has been slightly confusing to me, but the syntax auto&& might not mean an rvalue reference. According to the post, it means a universal reference. I wish they would have made a different syntax. For example, with templates, my understanding is:
void somefunction(int && i) // i is an rvalue reference
template<typename T>
void somefunction2(T && i) // i is a universal reference
It might be a similar thing with auto&&. So I would tentatively agree that std::forward should be used.
- lorenzhs 10y agoYes in this case it's a universal reference, I'm aware. Universal references work with auto&&. What std::forward does is the following: - if you put in an rvalue reference, it's like std::move - if you put in anything else, it does nothing. So my point about the article's formulation ("when you want to modify elements in the range in generic code") and its example remains.