| 175 | } // namespace pybind11 |
| 176 | |
| 177 | TEST_SUBMODULE(stl_binders, m) { |
| 178 | // test_vector_int |
| 179 | py::bind_vector<std::vector<unsigned int>>(m, "VectorInt", py::buffer_protocol()); |
| 180 | |
| 181 | // test_vector_custom |
| 182 | py::class_<El>(m, "El").def(py::init<int>()); |
| 183 | py::bind_vector<std::vector<El>>(m, "VectorEl"); |
| 184 | py::bind_vector<std::vector<std::vector<El>>>(m, "VectorVectorEl"); |
| 185 | |
| 186 | // test_map_string_double |
| 187 | py::bind_map<std::map<std::string, double>>(m, "MapStringDouble"); |
| 188 | py::bind_map<std::unordered_map<std::string, double>>(m, "UnorderedMapStringDouble"); |
| 189 | |
| 190 | // test_map_string_double_const |
| 191 | py::bind_map<std::map<std::string, double const>>(m, "MapStringDoubleConst"); |
| 192 | py::bind_map<std::unordered_map<std::string, double const>>(m, |
| 193 | "UnorderedMapStringDoubleConst"); |
| 194 | |
| 195 | // test_map_view_types |
| 196 | py::bind_map<std::map<std::string, float>>(m, "MapStringFloat"); |
| 197 | py::bind_map<std::unordered_map<std::string, float>>(m, "UnorderedMapStringFloat"); |
| 198 | |
| 199 | py::bind_map<std::map<std::pair<double, int>, int32_t>>(m, "MapPairDoubleIntInt32"); |
| 200 | py::bind_map<std::map<std::pair<double, int>, int64_t>>(m, "MapPairDoubleIntInt64"); |
| 201 | |
| 202 | py::bind_map<std::map<int, py::object>>(m, "MapIntObject"); |
| 203 | py::bind_map<std::map<std::string, py::object>>(m, "MapStringObject"); |
| 204 | |
| 205 | py::class_<E_nc>(m, "ENC").def(py::init<int>()).def_readwrite("value", &E_nc::value); |
| 206 | |
| 207 | // test_noncopyable_containers |
| 208 | py::bind_vector<std::vector<E_nc>>(m, "VectorENC"); |
| 209 | m.def("get_vnc", &one_to_n<std::vector<E_nc>>); |
| 210 | py::bind_vector<std::deque<E_nc>>(m, "DequeENC"); |
| 211 | m.def("get_dnc", &one_to_n<std::deque<E_nc>>); |
| 212 | py::bind_map<std::map<int, E_nc>>(m, "MapENC"); |
| 213 | m.def("get_mnc", ×_ten<std::map<int, E_nc>>); |
| 214 | py::bind_map<std::unordered_map<int, E_nc>>(m, "UmapENC"); |
| 215 | m.def("get_umnc", ×_ten<std::unordered_map<int, E_nc>>); |
| 216 | // Issue #1885: binding nested std::map<X, Container<E>> with E non-copyable |
| 217 | py::bind_map<std::map<int, std::vector<E_nc>>>(m, "MapVecENC"); |
| 218 | m.def("get_nvnc", [](int n) { |
| 219 | auto *m = new std::map<int, std::vector<E_nc>>(); |
| 220 | for (int i = 1; i <= n; i++) { |
| 221 | for (int j = 1; j <= n; j++) { |
| 222 | (*m)[i].emplace_back(j); |
| 223 | } |
| 224 | } |
| 225 | return m; |
| 226 | }); |
| 227 | py::bind_map<std::map<int, std::map<int, E_nc>>>(m, "MapMapENC"); |
| 228 | m.def("get_nmnc", ×_hundred<std::map<int, std::map<int, E_nc>>>); |
| 229 | py::bind_map<std::unordered_map<int, std::unordered_map<int, E_nc>>>(m, "UmapUmapENC"); |
| 230 | m.def("get_numnc", ×_hundred<std::unordered_map<int, std::unordered_map<int, E_nc>>>); |
| 231 | |
| 232 | // test_vector_buffer |
| 233 | py::bind_vector<std::vector<unsigned char>>(m, "VectorUChar", py::buffer_protocol()); |
| 234 | // no dtype declared for this version: |
nothing calls this directly
no test coverage detected