diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index bcaed97e9..a6153b807 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -378,15 +378,15 @@ public: #endif }; -template <> class type_caster : public type_caster { +template class type_caster> : public type_caster { public: - static PyObject *cast(const bytestring &src, return_value_policy /* policy */, PyObject * /* parent */) { - return PYBIND11_FROM_STRING_AND_SIZE(src.c_str(), src.size()); + static PyObject *cast(const bytes &src, return_value_policy /* policy */, PyObject * /* parent */) { + return PYBIND11_FROM_STRING_AND_SIZE(src.data(), src.size()); } #if PY_MAJOR_VERSION >= 3 - PYBIND11_TYPE_CASTER(bytestring, "bytes"); + PYBIND11_TYPE_CASTER(bytes, "bytes"); #else - PYBIND11_TYPE_CASTER(bytestring, "str"); + PYBIND11_TYPE_CASTER(bytes, "str"); #endif }; diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 154842348..0b1ad5e1c 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -259,13 +259,14 @@ inline iterator handle::end() { return iterator(nullptr); } PYBIND11_OBJECT(Name, Parent, CheckFun) \ Name() : Parent() { } -class bytestring : public std::string { +template +class bytes : public T { public: - using std::string::string; + using T::T; - bytestring(const std::string& src) : std::string(src) { } - bytestring(std::string&& src) : std::string(std::move(src)) { } - bytestring() : std::string() { } + bytes(const T& src) : T(src) { } + bytes(T&& src) : T(std::move(src)) { } + bytes() : T() { } }; class str : public object {