@@ -130,34 +130,30 @@ template <typename Map, typename holder_type = std::unique_ptr<Map>, typename...
130
130
py::class_<Map, holder_type> BindMap (py::handle scope, const std::string& name, Args&&... args) {
131
131
using Key = typename Map::key_type;
132
132
using Value = typename Map::mapped_type;
133
- auto cl =
134
- py::bind_map<Map, holder_type>(scope, name, std::forward<Args>(args)...)
135
- .def (py::init ([&](py::iterator it) {
136
- return MapFromIter<Map, Key>(it, MapCastValue<Map, Key, Value>);
137
- }),
138
- " iterator" _a)
139
- .def (py::init ([&](py::dict dict) {
140
- return MapFromDict<Map, Key>(dict, MapCastValue<Map, Key, Value>);
141
- }),
142
- " dictionary" _a)
143
- .def (py::self == py::self)
144
- .def (" clear" , &Map::clear)
145
- .def (
146
- " get" ,
147
- [](const Map& map, const Key& key,
148
- std::optional<py::object> default_value) -> std::variant<py::object, Value> {
149
- const auto it = map.find (key);
150
- if (it == map.cend ()) {
151
- if (default_value)
152
- return *default_value;
153
- throw py::key_error ();
154
- }
155
- return it->second ;
156
- },
157
- " key" _a, " default" _a = std::nullopt, py::keep_alive<0 , 1 >())
158
- .def (
159
- " keys" , [](const Map& map) { return py::make_key_iterator (map.begin (), map.end ()); },
160
- py::keep_alive<0 , 1 >());
133
+ auto cl = py::bind_map<Map, holder_type>(scope, name, std::forward<Args>(args)...)
134
+ .def (py::init ([&](py::iterator it) {
135
+ return MapFromIter<Map, Key>(it, MapCastValue<Map, Key, Value>);
136
+ }),
137
+ " iterator" _a)
138
+ .def (py::init ([&](py::dict dict) {
139
+ return MapFromDict<Map, Key>(dict, MapCastValue<Map, Key, Value>);
140
+ }),
141
+ " dictionary" _a)
142
+ .def (py::self == py::self)
143
+ .def (" clear" , &Map::clear)
144
+ .def (
145
+ " get" ,
146
+ [](const Map& map, const Key& key,
147
+ std::optional<py::object> default_value) -> std::variant<py::object, Value> {
148
+ const auto it = map.find (key);
149
+ if (it == map.cend ()) {
150
+ if (default_value)
151
+ return *default_value;
152
+ throw py::key_error ();
153
+ }
154
+ return it->second ;
155
+ },
156
+ " key" _a, " default" _a = std::nullopt, py::keep_alive<0 , 1 >());
161
157
py::implicitly_convertible<py::dict, Map>();
162
158
return cl;
163
159
}
0 commit comments