I wrote a simple function to calculate the min value of an std::initializer_list like this:
template<typename T> inline T min(const std::initializer_list<T>& values) { T minValue = values[0]; for ( const auto& v : values ) if ( v < minValue ) minValue = v; return minValue; } But I get the following errors:
error C2027: use of undefined type 'T'
error C2226: syntax error: unexpected type 'std::initializer<_Elem>'
error C2988: unrecognizable template declaration/definition
error C2059: syntax error: ')'
error C2143: syntax error: missing ';' before 'identifier'
I tried to change the std::initializer_list with an std::vector and there were no errors. Does this mean that we cannot define a template function using std::initializer_list as a parameter? I am using Visual Studio 2013.
initializer_listdoesn't haveoperator[]. Note also thatstd::minexists.min()functionminis inside a different namespace. And even if I remove everything inside the function and justreturn T();I still get the same errors