Is the following function safe in C++03 or C++11 or does it exhibit UB?
string const &min(string const &a, string const &b) { return a < b ? a : b; } int main() { cout << min("A", "B"); } Is it OK to return a reference to an object passed to the function by reference?
Is it guaranteed that the temporary
stringobject is not destroyed too soon?Is there any chance that the given function
mincould exhibit UB (if it does not in the given context)?Is it possible to make an equivalent, but safe function while still avoiding copying or moving?
std::strcmp().stringor other temporary object type. The question is meant to be general.