Adds automatic casting on assignment of non-pyobject types (#551)
This adds automatic casting when assigning to python types like dict,
list, and attributes. Instead of:
dict["key"] = py::cast(val);
m.attr("foo") = py::cast(true);
list.append(py::cast(42));
you can now simply write:
dict["key"] = val;
m.attr("foo") = true;
list.append(42);
Casts needing extra parameters (e.g. for a non-default rvp) still
require the py::cast() call. set::add() is also supported.
All usage is channeled through a SFINAE implementation which either just returns or casts.
Combined non-converting handle and autocasting template methods via a
helper method that either just returns (handle) or casts (C++ type).
diff --git a/tests/test_issues.cpp b/tests/test_issues.cpp
index 378da52..4c59a1b 100644
--- a/tests/test_issues.cpp
+++ b/tests/test_issues.cpp
@@ -381,6 +381,11 @@
.def_static("make", &MyDerived::make)
.def_static("make2", &MyDerived::make);
+ py::dict d;
+ std::string bar = "bar";
+ d["str"] = bar;
+ d["num"] = 3.7;
+
/// Issue #528: templated constructor
m2.def("tpl_constr_vector", [](std::vector<TplConstrClass> &) {});
m2.def("tpl_constr_map", [](std::unordered_map<TplConstrClass, TplConstrClass> &) {});