Given is a template function which checks if some elements stored in a container (specified by numElems
) are equal to any of the passed elements elems
.
template<typename MyType>
bool Container<MyType>::elemsEqual(const int & numElems, const std::initializer_list<MyType>& elems)
{
for (int i = 0; i < numElems; i++) {
const MyType& currElem = getElem(i);
if (std::none_of(elems.begin(), elems.end(), [](MyType& elem) {return currElem == elem; })) {
return false;
}
}
return true;
}
Compilation aborts with the error message:
'currElem' cannot be implicitly captured because no default capture mode has been specified
What is wrong here and how can I fix this problem?