| 2167 | }; |
| 2168 | |
| 2169 | class tuple : public object { |
| 2170 | public: |
| 2171 | PYBIND11_OBJECT_CVT(tuple, object, PyTuple_Check, PySequence_Tuple) |
| 2172 | template <typename SzType = ssize_t, |
| 2173 | detail::enable_if_t<std::is_integral<SzType>::value, int> = 0> |
| 2174 | // Some compilers generate link errors when using `const SzType &` here: |
| 2175 | explicit tuple(SzType size = 0) : object(PyTuple_New(ssize_t_cast(size)), stolen_t{}) { |
| 2176 | if (!m_ptr) { |
| 2177 | pybind11_fail("Could not allocate tuple object!"); |
| 2178 | } |
| 2179 | } |
| 2180 | size_t size() const { return static_cast<size_t>(PyTuple_Size(m_ptr)); } |
| 2181 | bool empty() const { return size() == 0; } |
| 2182 | detail::tuple_accessor operator[](size_t index) const { return {*this, index}; } |
| 2183 | template <typename T, detail::enable_if_t<detail::is_pyobject<T>::value, int> = 0> |
| 2184 | detail::item_accessor operator[](T &&o) const { |
| 2185 | return object::operator[](std::forward<T>(o)); |
| 2186 | } |
| 2187 | detail::tuple_iterator begin() const { return {*this, 0}; } |
| 2188 | detail::tuple_iterator end() const { return {*this, PyTuple_GET_SIZE(m_ptr)}; } |
| 2189 | }; |
| 2190 | |
| 2191 | // We need to put this into a separate function because the Intel compiler |
| 2192 | // fails to compile enable_if_t<all_of<is_keyword_or_ds<Args>...>::value> part below |
no outgoing calls