But. This is asinine:
#include
// somewhere in a function
size_t aNumber = 5; // perfectly fine
...
return std::min(1, aNumber); // compile-error
The reason this is giving me a compile error is because I'm passing mismatched types to std::min and it can't figure out the type deduction. That is to say, it thinks that "1" is an int, and only an int. The variable, on the other hand, is not an int, it's a "size_t" (AKA "unsigned long", varying from an int in size and sign). However, when the type has been declared, the compiler has no problem assigning a constant to the size_t.
The solution?
return std::min(1ul, aNumber);
Lame. I don't think you needed to do this back in the day, when compilers were worse. Of course, you did have to make the call to std::min
No comments:
Post a Comment