MCPcopy Create free account
hub / github.com/pybind/pybind11 / bool_

Class bool_

include/pybind11/pytypes.h:1887–1906  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1885};
1886
1887class bool_ : public object {
1888public:
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
1897private:
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
1908PYBIND11_NAMESPACE_BEGIN(detail)
1909// Converts a value to the given unsigned type. If an error occurs, you get back (Unsigned) -1;

Callers 4

castMethod · 0.85
castMethod · 0.85
TEST_SUBMODULEFunction · 0.85
TEST_SUBMODULEFunction · 0.85

Calls

no outgoing calls

Tested by 4

castMethod · 0.68
castMethod · 0.68
TEST_SUBMODULEFunction · 0.68
TEST_SUBMODULEFunction · 0.68