I wanted to find a convenient way to check if a value was in a set of values. If I create a simple function like the following, everything works well:
bool IsIn(const int& value, initializer_list<int> initializerList)
{
vector<int> v(initializerList);
return find(v.begin(), v.end(), value) != v.end();
}
bool MyFunction()
{
return IsIn(1, { 1,2,3 });
}
if I now turn this function into a more user-friendly operator >>, i get an error C2059: syntax error: '{'
bool operator >>(const int& value, initializer_list<int> initializerList)
{
vector<int> v(initializerList);
return find(v.begin(), v.end(), value) != v.end();
}
bool MyFunction()
{
return 1 >> { 1, 2, 3 };
}
I did not find in C++ specification that the use of a initializer list as parameter was limited to "normal" functions. Is this a bug or am I doing something wrong? (I am using VS2017)