| 1924 | PYBIND11_NAMESPACE_END(detail) |
| 1925 | |
| 1926 | class int_ : public object { |
| 1927 | public: |
| 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 | |
| 1961 | class float_ : public object { |
| 1962 | public: |
no outgoing calls