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

Class int_

include/pybind11/pytypes.h:1926–1959  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1924PYBIND11_NAMESPACE_END(detail)
1925
1926class int_ : public object {
1927public:
1928 PYBIND11_OBJECT_CVT(int_, object, PYBIND11_LONG_CHECK, PyNumber_Long)
1929 int_() : object(PyLong_FromLong(0), stolen_t{}) {}
1930 // Allow implicit conversion from C++ integral types:
1931 template <typename T, detail::enable_if_t<std::is_integral<T>::value, int> = 0>
1932 // NOLINTNEXTLINE(google-explicit-constructor)
1933 int_(T value) {
1934 if (sizeof(T) <= sizeof(long)) {
1935 if (std::is_signed<T>::value) {
1936 m_ptr = PyLong_FromLong((long) value);
1937 } else {
1938 m_ptr = PyLong_FromUnsignedLong((unsigned long) value);
1939 }
1940 } else {
1941 if (std::is_signed<T>::value) {
1942 m_ptr = PyLong_FromLongLong((long long) value);
1943 } else {
1944 m_ptr = PyLong_FromUnsignedLongLong((unsigned long long) value);
1945 }
1946 }
1947 if (!m_ptr) {
1948 pybind11_fail("Could not allocate int object!");
1949 }
1950 }
1951
1952 template <typename T, detail::enable_if_t<std::is_integral<T>::value, int> = 0>
1953 // NOLINTNEXTLINE(google-explicit-constructor)
1954 operator T() const {
1955 return std::is_unsigned<T>::value ? detail::as_unsigned<T>(m_ptr)
1956 : sizeof(T) <= sizeof(long) ? (T) PyLong_AsLong(m_ptr)
1957 : (T) PYBIND11_LONG_AS_LONGLONG(m_ptr);
1958 }
1959};
1960
1961class float_ : public object {
1962public:

Callers 15

TEST_SUBMODULEFunction · 0.85
TEST_SUBMODULEFunction · 0.85
TEST_SUBMODULEFunction · 0.85
TEST_SUBMODULEFunction · 0.85
test_class.cppFile · 0.85
test_dtype_ctorsFunction · 0.85
TEST_SUBMODULEFunction · 0.85
enum_nameFunction · 0.85
initFunction · 0.85
pybind11.hFile · 0.85
export_valuesFunction · 0.85

Calls

no outgoing calls

Tested by 6

TEST_SUBMODULEFunction · 0.68
TEST_SUBMODULEFunction · 0.68
TEST_SUBMODULEFunction · 0.68
TEST_SUBMODULEFunction · 0.68
test_dtype_ctorsFunction · 0.68
TEST_SUBMODULEFunction · 0.68