11 #include <initializer_list>
14 #include <type_traits>
30 #if OIIO_VERSION_GREATER_EQUAL(3,0,0)
31 # define OIIO_SPAN_SIZE_IS_UNSIGNED
34 #ifdef OIIO_SPAN_SIZE_IS_UNSIGNED
72 template <
typename T, oiio_span_
size_type Extent = dynamic_extent>
80 #if OIIO_VERSION < OIIO_MAKE_VERSION(3,0,0)
92 constexpr
span () noexcept { }
95 template<
class U, oiio_span_
size_type N>
97 : m_data(
copy.data()), m_size(
copy.size()) { }
107 : m_data(
b), m_size(e-
b) { }
118 template<
class Allocator>
119 constexpr
span (std::vector<T, Allocator> &
v)
120 : m_data(v.
size() ? &v[0] : nullptr), m_size(v.
size()) {
126 template<
class Allocator>
127 span (
const std::vector<value_type, Allocator> &
v)
128 : m_data(v.
size() ? &v[0] : nullptr), m_size(v.
size()) { }
132 constexpr
span (std::array<value_type, N> &arr)
133 : m_data(arr.
data()), m_size(
N) {}
137 constexpr
span (
const std::array<value_type, N>& arr)
138 : m_data(arr.
data()), m_size(
N) {}
141 constexpr
span (std::initializer_list<T> il)
146 m_data = copy.
data();
147 m_size = copy.
size();
152 template<
size_type Count>
154 return { m_data,
Count };
157 template<
size_type Count>
159 return { m_data + m_size -
Count, Count };
162 template<
size_type Offset,
size_type Count = dynamic_extent>
168 return { m_data, count };
172 return { m_data + ( m_size -
count ), count };
187 constexpr
bool empty() const noexcept {
return m_size == 0; }
195 throw (std::out_of_range (
"OpenImageIO::span::at"));
203 constexpr
iterator end() const noexcept {
return m_data + m_size; }
222 template <
typename T>
228 template <
class T, oiio_span_
size_type X,
class U, oiio_span_
size_type Y>
230 #if OIIO_CPLUSPLUS_VERSION >= 20
233 auto lsize = l.
size();
234 bool same = (lsize == r.
size());
235 for (ptrdiff_t i = 0; same && i < lsize; ++i)
236 same &= (l[i] == r[i]);
242 template <
class T, oiio_span_
size_type X,
class U, oiio_span_
size_type Y>
253 template <
typename T, oiio_span_
size_type Extent = dynamic_extent>
256 "can't have span_strided of an array");
262 #if OIIO_VERSION < OIIO_MAKE_VERSION(3,0,0)
279 : m_data(copy.
data()), m_size(copy.
size()), m_stride(copy.
stride()) {}
283 : m_data(data), m_size(size), m_stride(
stride) { }
294 template<
class Allocator>
296 : span_strided(v.
size() ? &v[0] : nullptr, v.
size(), 1) {}
301 template<
class Allocator>
303 : span_strided(v.
size() ? &v[0] : nullptr, v.
size(), 1) {}
307 : span_strided (il.
begin(), il.
size()) { }
311 : span_strided(av.
data(), av.
size(), 1) { }
315 m_data = copy.
data();
316 m_size = copy.
size();
325 return m_data[m_stride*idx];
328 return m_data[m_stride*idx];
332 throw (std::out_of_range (
"OpenImageIO::span_strided::at"));
333 return m_data[m_stride*idx];
342 stride_type m_stride = 1;
348 template <
typename T>
354 template <
class T, oiio_span_
size_type X,
class U, oiio_span_
size_type Y>
356 auto lsize = l.
size();
357 if (lsize != r.
size())
359 for (ptrdiff_t i = 0; i < lsize; ++i)
366 template <
class T, oiio_span_
size_type X,
class U, oiio_span_
size_type Y>
379 template<
class T, OIIO::oiio_span_
size_type E = OIIO::dynamic_extent>
380 constexpr
size_t size(
const OIIO::span<T, E>&
c) {
381 return static_cast<size_t>(c.size());
384 template<
class T, OIIO::oiio_span_
size_type E = OIIO::dynamic_extent>
385 constexpr
size_t size(
const OIIO::span_strided<T, E>&
c) {
386 return static_cast<size_t>(c.size());
390 #if OIIO_CPLUSPLUS_VERSION < 20
392 template<
class T, OIIO::oiio_span_
size_type E = OIIO::dynamic_extent>
393 constexpr ptrdiff_t
ssize(
const OIIO::span<T, E>&
c) {
394 return static_cast<ptrdiff_t
>(c.size());
397 template<
class T, OIIO::oiio_span_
size_type E = OIIO::dynamic_extent>
398 constexpr ptrdiff_t
ssize(
const OIIO::span_strided<T, E>&
c) {
399 return static_cast<ptrdiff_t
>(c.size());
405 #define OIIO_SPAN_HAS_STD_SIZE 1
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