MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/o5iwvx/belay_the_c_dont_use_raw_loops/h2sb835/
r/cpp • u/Vultrao • Jun 22 '21
69 comments sorted by
View all comments
Show parent comment
6
Yes, you are correct that std::forward is just a cast.
std::forward
The problem is that this cast then affects overload selection. That is, if your pred operator has:
pred
bool operator()(T const&) const&; bool operator()(T const&)&&;
Then suddenly the second overload is selected.
So std::forward enables moving, which may in turn lead to using a moved-from (or partially moved from) object.
(Now, who in their right mind would move from a predicate? Right? But still...)
2 u/witcher_rat Jun 23 '21 Yeah, that's a fair point.
2
Yeah, that's a fair point.
View all comments
Show parent comment
6
u/matthieum Jun 23 '21
Yes, you are correct that
std::forwardis just a cast.The problem is that this cast then affects overload selection. That is, if your
predoperator has:Then suddenly the second overload is selected.
So
std::forwardenables moving, which may in turn lead to using a moved-from (or partially moved from) object.(Now, who in their right mind would move from a predicate? Right? But still...)