Added __contains__ to stl bindings for maps (#1767)

* Added __contains__ to stl bindings for maps
This commit is contained in:
Blake Thompson
2019-06-10 14:01:11 -05:00
committed by Wenzel Jakob
parent c251434011
commit 30c0352348
2 changed files with 11 additions and 0 deletions

View File

@@ -579,6 +579,15 @@ class_<Map, holder_type> bind_map(handle scope, const std::string &name, Args&&.
return_value_policy::reference_internal // ref + keepalive
);
cl.def("__contains__",
[](Map &m, const KeyType &k) -> bool {
auto it = m.find(k);
if (it == m.end())
return false;
return true;
}
);
// Assignment provided only if the type is copyable
detail::map_assignment<Map, Class_>(cl);