11 #include <initializer_list>
14 #include <type_traits>
31 #if OIIO_VERSION_GREATER_EQUAL(3,0,0)
32 # define OIIO_SPAN_SIZE_IS_UNSIGNED
35 #ifdef OIIO_SPAN_SIZE_IS_UNSIGNED
73 template <
typename T, oiio_span_
size_type Extent = dynamic_extent>
81 #if OIIO_VERSION < OIIO_MAKE_VERSION(3,0,0)
93 constexpr
span () noexcept { }
96 template<
class U, oiio_span_
size_type N>
98 : m_data(
copy.data()), m_size(
copy.size()) { }
108 : m_data(
b), m_size(e-
b) { }
119 template<
class Allocator>
120 constexpr
span (std::vector<T, Allocator> &
v)
121 : m_data(v.
size() ? &v[0] : nullptr), m_size(v.
size()) {
127 template<
class Allocator>
128 span (
const std::vector<value_type, Allocator> &
v)
129 : m_data(v.
size() ? &v[0] : nullptr), m_size(v.
size()) { }
133 constexpr
span (std::array<value_type, N> &arr)
134 : m_data(arr.
data()), m_size(
N) {}
138 constexpr
span (
const std::array<value_type, N>& arr)
139 : m_data(arr.
data()), m_size(
N) {}
142 constexpr
span (std::initializer_list<T> il)
147 m_data = copy.
data();
148 m_size = copy.
size();
153 template<
size_type Count>
155 return { m_data,
Count };
158 template<
size_type Count>
160 return { m_data + m_size -
Count, Count };
163 template<
size_type Offset,
size_type Count = dynamic_extent>
169 return { m_data, count };
173 return { m_data + ( m_size -
count ), count };
188 constexpr
bool empty() const noexcept {
return m_size == 0; }
196 throw (std::out_of_range (
"OpenImageIO::span::at"));
204 constexpr
iterator end() const noexcept {
return m_data + m_size; }
223 template <
typename T, oiio_span_
size_type Extent = dynamic_extent>
229 template <
class T, oiio_span_
size_type X,
class U, oiio_span_
size_type Y>
231 #if OIIO_CPLUSPLUS_VERSION >= 20
234 auto lsize = l.
size();
235 bool same = (lsize == r.
size());
236 for (ptrdiff_t i = 0; same && i < lsize; ++i)
237 same &= (l[i] == r[i]);
243 template <
class T, oiio_span_
size_type X,
class U, oiio_span_
size_type Y>
254 template <
typename T, oiio_span_
size_type Extent = dynamic_extent>
257 "can't have span_strided of an array");
263 #if OIIO_VERSION < OIIO_MAKE_VERSION(3,0,0)
280 : m_data(copy.
data()), m_size(copy.
size()), m_stride(copy.
stride()) {}
284 : m_data(data), m_size(size), m_stride(
stride) { }
295 template<
class Allocator>
297 : span_strided(v.
size() ? &v[0] : nullptr, v.
size(), 1) {}
302 template<
class Allocator>
304 : span_strided(v.
size() ? &v[0] : nullptr, v.
size(), 1) {}
308 : span_strided (il.
begin(), il.
size()) { }
312 : span_strided(av.
data(), av.
size(), 1) { }
316 m_data = copy.
data();
317 m_size = copy.
size();
326 return m_data[m_stride*idx];
329 return m_data[m_stride*idx];
333 throw (std::out_of_range (
"OpenImageIO::span_strided::at"));
334 return m_data[m_stride*idx];
343 stride_type m_stride = 1;
349 template <
typename T, oiio_span_
size_type Extent = dynamic_extent>
355 template <
class T, oiio_span_
size_type X,
class U, oiio_span_
size_type Y>
357 auto lsize = l.
size();
358 if (lsize != r.
size())
360 for (ptrdiff_t i = 0; i < lsize; ++i)
367 template <
class T, oiio_span_
size_type X,
class U, oiio_span_
size_type Y>
380 template<
class T, OIIO::oiio_span_
size_type E = OIIO::dynamic_extent>
381 constexpr
size_t size(
const OIIO::span<T, E>&
c) {
382 return static_cast<size_t>(c.size());
385 template<
class T, OIIO::oiio_span_
size_type E = OIIO::dynamic_extent>
386 constexpr
size_t size(
const OIIO::span_strided<T, E>&
c) {
387 return static_cast<size_t>(c.size());
391 #if OIIO_CPLUSPLUS_VERSION < 20
393 template<
class T, OIIO::oiio_span_
size_type E = OIIO::dynamic_extent>
394 constexpr ptrdiff_t
ssize(
const OIIO::span<T, E>&
c) {
395 return static_cast<ptrdiff_t
>(c.size());
398 template<
class T, OIIO::oiio_span_
size_type E = OIIO::dynamic_extent>
399 constexpr ptrdiff_t
ssize(
const OIIO::span_strided<T, E>&
c) {
400 return static_cast<ptrdiff_t
>(c.size());
406 #define OIIO_SPAN_HAS_STD_SIZE 1
416 template<
typename T, OIIO::oiio_span_
size_type Extent>
418 : OIIO::pvt::index_formatter<OIIO::span<T, Extent>> {};
constexpr span(std::array< value_type, N > &arr)
Construct from mutable element std::array.
constexpr const_iterator cend() const noexcept
typename std::remove_cv< T >::type value_type
constexpr iterator end() const noexcept
constexpr span(std::vector< T, Allocator > &v)
Construct from std::vector<T>.
constexpr span_strided(const span_strided ©)
Copy constructor.
constexpr span< element_type, dynamic_extent > subspan(size_type offset, size_type count=dynamic_extent) const
ptrdiff_t difference_type
constexpr span< element_type, Count > first() const
Subview containing the first Count elements of the span.
span & operator=(const span ©)
Assignment copies the pointer and length, not the data.
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
GLsizei const GLfloat * value
constexpr span_strided(T(&data)[N])
constexpr span_strided(pointer data, size_type size, stride_type stride=1)
Construct from T* and size, and optionally stride.
constexpr span< element_type, Count > subspan() const
typename std::remove_cv< unsigned char >::type value_type
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
constexpr span_strided() noexcept
Default ctr – points to nothing.
constexpr size_type size() const noexcept
constexpr span_strided(span< T > av)
Initialize from an span (stride will be 1).
std::reverse_iterator< iterator > reverse_iterator
ptrdiff_t oiio_span_size_type
ptrdiff_t difference_type
constexpr const_iterator cbegin() const noexcept
constexpr reference back() const noexcept
constexpr span(std::initializer_list< T > il)
Construct an span from an initializer_list.
std::reverse_iterator< const_iterator > const_reverse_iterator
OIIO_CONSTEXPR14 bool operator==(span< T, X > l, span< U, Y > r)
Compare all elements of two spans for equality.
constexpr reference operator()(size_type idx) const
OIIO_CONSTEXPR14 bool operator!=(span< T, X > l, span< U, Y > r)
Compare all elements of two spans for inequality.
OIIO_CONSTEXPR14 span_strided(std::vector< T, Allocator > &v)
Construct from std::vector<T>.
constexpr iterator begin() const noexcept
OIIO_INLINE_CONSTEXPR oiio_span_size_type dynamic_extent
constexpr span< element_type, Count > last() const
Subview containing the last Count elements of the span.
constexpr pointer data() const noexcept
const element_type * const_iterator
constexpr const_reverse_iterator crend() const noexcept
constexpr reference operator[](size_type idx) const
GLint GLenum GLboolean GLsizei stride
constexpr span_strided(const std::vector< value_type, Allocator > &v)
const element_type * const_iterator
constexpr span(T &data)
Construct from a single T&.
constexpr size_type size() const noexcept
constexpr reverse_iterator rbegin() const noexcept
constexpr span< element_type, dynamic_extent > last(size_type count) const
GLboolean GLboolean GLboolean b
constexpr span_strided(std::initializer_list< T > il)
Construct an span from an initializer_list.
constexpr span(const std::array< value_type, N > &arr)
Construct from read-only element std::array.
static constexpr size_type extent
unsigned char element_type
std::reverse_iterator< const_iterator > const_reverse_iterator
oiio_span_size_type size_type
constexpr ptrdiff_t ssize(const OIIO::span_strided< T, E > &c)
reference at(size_type idx) const
constexpr span(const span< U, N > ©) noexcept
Copy constructor (copies the span pointer and length, NOT the data).
constexpr reference back() const noexcept
constexpr span(T(&data)[N])
reference at(size_type idx) const
constexpr span(pointer data, size_type size) noexcept
Construct from T* and length.
oiio_span_size_type size_type
constexpr size_type size_bytes() const noexcept
constexpr reference front() const noexcept
constexpr span_strided(T &data)
Construct from a single T&.
GA_API const UT_StringHolder N
constexpr span< element_type, dynamic_extent > first(size_type count) const
span(const std::vector< value_type, Allocator > &v)
constexpr bool empty() const noexcept
constexpr span(pointer b, pointer e) noexcept
Construct from begin and end pointers.
constexpr reference front() const noexcept
#define OIIO_NAMESPACE_END
constexpr span() noexcept
Default constructor – the span points to nothing.
constexpr reverse_iterator rend() const noexcept
constexpr pointer data() const noexcept
constexpr const_reverse_iterator crbegin() const noexcept
#define OIIO_NAMESPACE_BEGIN
constexpr stride_type stride() const noexcept
std::reverse_iterator< iterator > reverse_iterator