mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-11 08:03:55 +00:00
minor enum_ improvement (use __repr__ instead of __str__)
This commit is contained in:
parent
bcd3182f3d
commit
8456a4dca2
@ -813,7 +813,7 @@ public:
|
|||||||
enum_(object &scope, const char *name, const char *doc = nullptr)
|
enum_(object &scope, const char *name, const char *doc = nullptr)
|
||||||
: class_<Type>(scope, name, doc), m_parent(scope) {
|
: class_<Type>(scope, name, doc), m_parent(scope) {
|
||||||
auto entries = new std::unordered_map<int, const char *>();
|
auto entries = new std::unordered_map<int, const char *>();
|
||||||
this->def("__str__", [name, entries](Type value) -> std::string {
|
this->def("__repr__", [name, entries](Type value) -> std::string {
|
||||||
auto it = entries->find((int) value);
|
auto it = entries->find((int) value);
|
||||||
return std::string(name) + "." +
|
return std::string(name) + "." +
|
||||||
((it == entries->end()) ? std::string("???")
|
((it == entries->end()) ? std::string("???")
|
||||||
|
Loading…
Reference in New Issue
Block a user