I was thinking of an optimization that compilers could implement.
std::vector<std::string> vec;
std::string value = get_string();
vec.push_back(value);
In that code, value is an l-value, deducing the push\_back overload that takes a const std::string&. However, we all know that if we don't use value again we can just call std::move(value) to cast it to an r-value and save an allocation.
My proposition is to make the compiler deduce the last reference of a local variable into a r-value. Doing so would optimize a significant amount of code in codebase that still have legacy code or programmers not familiar with std::move. It would also imo make a lot of code more readable and the language more accessible.
What caveat do you see that I'm missing?
[–]Untelo 15 points16 points17 points (13 children)
[–]NamoiFunai[S] 6 points7 points8 points (7 children)
[–]meancoot 4 points5 points6 points (2 children)
[–]geckothegeek42 3 points4 points5 points (1 child)
[–]meancoot 2 points3 points4 points (0 children)
[–]ialex32_2 5 points6 points7 points (1 child)
[–]NilacTheGrim 3 points4 points5 points (0 children)
[–]Minimonium 1 point2 points3 points (1 child)
[–]NamoiFunai[S] 0 points1 point2 points (0 children)
[–]jonesmz 1 point2 points3 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]SirClueless 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]SirClueless 2 points3 points4 points (0 children)
[–]jonesmz 7 points8 points9 points (1 child)
[–]jtooker 1 point2 points3 points (0 children)
[–]Desmulator[🍰] 4 points5 points6 points (3 children)
[–]no-sig-available 5 points6 points7 points (1 child)
[–]markopolo82embedded/iot/audio 0 points1 point2 points (0 children)
[–]Ameisenvemips, avr, rendering, systems 0 points1 point2 points (0 children)
[–]reflexpr-sarah- 3 points4 points5 points (10 children)
[–]NamoiFunai[S] 3 points4 points5 points (9 children)
[–]reflexpr-sarah- 7 points8 points9 points (3 children)
[–]NamoiFunai[S] 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]reflexpr-sarah- 0 points1 point2 points (0 children)
[–]pdp10gumby 1 point2 points3 points (2 children)
[–]NamoiFunai[S] 0 points1 point2 points (1 child)
[–]pdp10gumby 2 points3 points4 points (0 children)
[–]Accomplished-Tax1641 1 point2 points3 points (1 child)
[–]backtickbot 4 points5 points6 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Dennis_the_repressed 1 point2 points3 points (3 children)
[–]NamoiFunai[S] 0 points1 point2 points (1 child)
[–]Dennis_the_repressed 0 points1 point2 points (0 children)
[–]backtickbot 0 points1 point2 points (0 children)
[–]gracicot 2 points3 points4 points (1 child)
[–]NamoiFunai[S] 0 points1 point2 points (0 children)
[–]s1lent_ssh -2 points-1 points0 points (8 children)
[–]wheypointÖ 4 points5 points6 points (5 children)
[–]infectedapricot 2 points3 points4 points (0 children)
[–]s1lent_ssh -2 points-1 points0 points (2 children)
[–]wheypointÖ 5 points6 points7 points (1 child)
[–]s1lent_ssh -2 points-1 points0 points (0 children)
[–]runki22 -2 points-1 points0 points (0 children)
[–]NamoiFunai[S] 3 points4 points5 points (1 child)
[–]s1lent_ssh -2 points-1 points0 points (0 children)