You should add an error message to your question ...
Anyway, I used CLang ++ to compile it, and the error is:
test.cpp:47:5: error: no matching function for call to 'RemoveValue' RemoveValue(entityToTags, &entity, tag, [&](const Tag &t) { return t == tag; }); ^~~~~~~~~~~ test.cpp:15:6: note: candidate template ignored: could not match 'function<bool (const type-parameter-0-0 &)>' against '<lambda at t.cpp:47:45>' void RemoveValue(
That is, to infer the type Tag , the compiler must use the third argument Tag and the fourth. The latter is of type std::function<bool(const Value&)> , but you pass a lambda. Yes, lambda is converted to this type, but it is not that type, therefore the automatic output for Tag fails.
The solution would be to pass a value of the real type std::function<bool(const Value&)> :
std::function<bool(const Tag&)> f = [&](const Tag &t) { return &t == &tag; }; RemoveValue(entityToTags, &entity, tag, f);
Or use static_cast<>() if you want, but I would find this line too long.
source share