Following https://stackoverflow.com/a/9424211/3368959 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?
As @BoBTFish suggested:
In order to use template <class T> T min (initializer_list<T> il)
one needs to include <algorithm>
as is mentioned here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With