Following https://mcmap.net/q/377885/-find-the-smallest-amongst-3-numbers-in-c-duplicate I am trying to compare three numbers:
#include <iostream>
int main() {
std::cout << std::min({2,5,1}) << std::endl;
return 0;
}
But the compiler gives me the error:
error: no matching function for call to ‘min(<brace-enclosed initializer list>)’
However, the code compiles just fine when using
std::min(std::min(2,5),1)
But the first way should work with the c++11 standard. What could I be doing wrong?
#include <algorithm>
? As to why it works using the 2-arg version, I can only assume the implementation of the Standard Library you are using splits the algorithm header up in some way, and you are getting some transitive include throughiostream
, but this is certainly not guaranteed to work. – Ferris