| 1869 | PYBIND11_NAMESPACE_END(detail) |
| 1870 | |
| 1871 | class int_ : public object { |
| 1872 | public: |
| 1873 | PYBIND11_OBJECT_CVT(int_, object, PYBIND11_LONG_CHECK, PyNumber_Long) |
| 1874 | int_() : object(PyLong_FromLong(0), stolen_t{}) {} |
| 1875 | // Allow implicit conversion from C++ integral types: |
| 1876 | template <typename T, detail::enable_if_t<std::is_integral<T>::value, int> = 0> |
| 1877 | // NOLINTNEXTLINE(google-explicit-constructor) |
| 1878 | int_(T value) { |
| 1879 | if (sizeof(T) <= sizeof(long)) { |
| 1880 | if (std::is_signed<T>::value) { |
| 1881 | m_ptr = PyLong_FromLong((long) value); |
| 1882 | } else { |
| 1883 | m_ptr = PyLong_FromUnsignedLong((unsigned long) value); |
| 1884 | } |
| 1885 | } else { |
| 1886 | if (std::is_signed<T>::value) { |
| 1887 | m_ptr = PyLong_FromLongLong((long long) value); |
| 1888 | } else { |
| 1889 | m_ptr = PyLong_FromUnsignedLongLong((unsigned long long) value); |
| 1890 | } |
| 1891 | } |
| 1892 | if (!m_ptr) { |
| 1893 | pybind11_fail("Could not allocate int object!"); |
| 1894 | } |
| 1895 | } |
| 1896 | |
| 1897 | template <typename T, detail::enable_if_t<std::is_integral<T>::value, int> = 0> |
| 1898 | // NOLINTNEXTLINE(google-explicit-constructor) |
| 1899 | operator T() const { |
| 1900 | return std::is_unsigned<T>::value ? detail::as_unsigned<T>(m_ptr) |
| 1901 | : sizeof(T) <= sizeof(long) ? (T) PyLong_AsLong(m_ptr) |
| 1902 | : (T) PYBIND11_LONG_AS_LONGLONG(m_ptr); |
| 1903 | } |
| 1904 | }; |
| 1905 | |
| 1906 | class float_ : public object { |
| 1907 | public: |
no outgoing calls
no test coverage detected