Created
May 16, 2014 21:17
-
-
Save trainman419/d8cf0c0f17dc05a8f940 to your computer and use it in GitHub Desktop.
Don't store the result of std::min in a const &
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <algorithm> | |
class B { | |
public: | |
int b_; | |
B(int b) : b_(b) {} | |
~B() { b_ = 23; } | |
bool operator<(const B & o) const { | |
return b_ < o.b_; | |
} | |
}; | |
int main() { | |
const B & m = std::min(B(3), B(5)); | |
printf("min %d\n", m.b_); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More like "don't pass temporaries into std::min and expect to use a reference to the result"