using type_caster with custom fundamental types (library called type_safe) #3930
-
Guys I have a library depending on another one called type_safe which is a wrapper around fundamental types. So basically these types needs to be binded via void set(type_safe::float_t a) {
} Any ideas? #include <type_safe/floating_point.hpp>
namespace pybind11 {
namespace detail {
template <>
struct type_caster<type_safe::floating_point<float>> {
public:
using floating_point_type = type_safe::floating_point<float>;
PYBIND11_TYPE_CASTER(floating_point_type, const_name("floating_point<float>"));
bool load(handle src, bool) {
PyObject* source = src.ptr();
PyObject* tmp = PyNumber_Float(source);
if (!tmp) {
return false;
}
value = (float)PyFloat_AsDouble(tmp);
Py_DECREF(tmp);
return !(value.get() == -1 && !PyErr_Occurred());
}
static handle cast(const floating_point_type& src, return_value_policy, handle) {
return PyFloat_FromDouble(src.get());
}
};
} // namespace detail
} // namespace pybind11 By the way, is there a way to partially specialize |
Beta Was this translation helpful? Give feedback.
#1036