| 1885 | }; |
| 1886 | |
| 1887 | class bool_ : public object { |
| 1888 | public: |
| 1889 | PYBIND11_OBJECT_CVT(bool_, object, PyBool_Check, raw_bool) |
| 1890 | bool_() : object(Py_False, borrowed_t{}) {} |
| 1891 | // Allow implicit conversion from and to `bool`: |
| 1892 | // NOLINTNEXTLINE(google-explicit-constructor) |
| 1893 | bool_(bool value) : object(value ? Py_True : Py_False, borrowed_t{}) {} |
| 1894 | // NOLINTNEXTLINE(google-explicit-constructor) |
| 1895 | operator bool() const { return (m_ptr != nullptr) && PyLong_AsLong(m_ptr) != 0; } |
| 1896 | |
| 1897 | private: |
| 1898 | /// Return the truth value of an object -- always returns a new reference |
| 1899 | static PyObject *raw_bool(PyObject *op) { |
| 1900 | const auto value = PyObject_IsTrue(op); |
| 1901 | if (value == -1) { |
| 1902 | return nullptr; |
| 1903 | } |
| 1904 | return handle(value != 0 ? Py_True : Py_False).inc_ref().ptr(); |
| 1905 | } |
| 1906 | }; |
| 1907 | |
| 1908 | PYBIND11_NAMESPACE_BEGIN(detail) |
| 1909 | // Converts a value to the given unsigned type. If an error occurs, you get back (Unsigned) -1; |
no outgoing calls