7#ifndef PXR_BASE_TF_SPAN_H
8#define PXR_BASE_TF_SPAN_H
13#include "pxr/base/tf/api.h"
21PXR_NAMESPACE_OPEN_SCOPE
73 using element_type = T;
74 using value_type =
typename std::remove_cv<T>::type;
77 using index_type = std::size_t;
78 using difference_type = std::ptrdiff_t;
81 using const_iterator =
const T*;
82 using reverse_iterator = std::reverse_iterator<iterator>;
83 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
85 TfSpan()
noexcept =
default;
90 TfSpan(pointer ptr, index_type count)
91 : _data(ptr), _size(count)
106 template <
class Container>
108 typename std::enable_if<
109 !std::is_const<element_type>::value &&
110 std::is_same<
typename Container::value_type, value_type
113 : _data(cont.
data()), _size(cont.
size())
121 template <
class Container>
123 typename std::enable_if<
124 std::is_same<
typename Container::value_type, value_type
127 : _data(cont.
data()), _size(cont.
size())
133 pointer
data() const noexcept {
return _data; }
136 index_type
size() const noexcept {
return _size; }
139 bool empty() const noexcept {
return _size == 0; }
162 iterator
begin() const noexcept {
return _data; }
165 const_iterator
cbegin() const noexcept {
return _data; }
168 iterator
end() const noexcept {
return _data + _size; }
171 const_iterator
cend() const noexcept {
return _data + _size; }
175 {
return reverse_iterator(
end()); }
178 const_reverse_iterator
crbegin() const noexcept
179 {
return const_reverse_iterator(
cend()); }
182 reverse_iterator
rend() const noexcept
183 {
return reverse_iterator(
begin()); }
186 const_reverse_iterator
crend() const noexcept
187 {
return const_reverse_iterator(
cbegin()); }
194 TF_DEV_AXIOM(offset >= 0 && (index_type)offset < _size);
196 return TfSpan<T>(_data + offset, _size - offset);
199 TF_DEV_AXIOM(((index_type)offset+(index_type)count) <= _size);
216 pointer _data =
nullptr;
217 index_type _size = 0;
222template <
typename Container>
231template <
typename Container>
238PXR_NAMESPACE_CLOSE_SCOPE
Low-level utilities for informing users of various internal and external diagnostic conditions.
Represents a range of contiguous elements.
reference front() const
Return a reference to the first element in the span.
TfSpan(pointer first, pointer last)
Construct a span over the range [first, last).
reverse_iterator rbegin() const noexcept
Returns a non-const reverse iterator the start of the span.
bool empty() const noexcept
Returns true if this span contains no elements, false otherwise.
TfSpan< T > first(size_t count) const
Return a subspan consisting of the first count elements of this span.
index_type size() const noexcept
Return the total number of elements in the span.
TfSpan(pointer ptr, index_type count)
Construct a span over the range of [ptr, ptr+count).
reverse_iterator rend() const noexcept
Returns a non-const reverse iterator to the end of the span.
TfSpan< T > subspan(difference_type offset, difference_type count=-1) const
Returns a new span referencing a sub-range of this span.
reference operator[](index_type idx) const
Returns a reference to the idx'th element of the span.
const_iterator cend() const noexcept
Returns a const iterator to the end of the span.
reference back() const
Return a reference to the last element in the span.
pointer data() const noexcept
Return a pointer to the first element of the span.
TfSpan< T > last(size_t count) const
Return a subspan consisting of the last count elements of this span.
TfSpan(const Container &cont, typename std::enable_if< std::is_same< typename Container::value_type, value_type >::value, Container >::type *=0)
Construct a span from a container.
iterator end() const noexcept
Returns a non-const iterator to the end of the span.
const_reverse_iterator crbegin() const noexcept
Returns a cons reverse iterator to the start of the span.
const_iterator cbegin() const noexcept
Returns a cons iterator to the start of the span.
const_reverse_iterator crend() const noexcept
Returns a const reverse iterator to the end of the span.
TfSpan(Container &cont, typename std::enable_if< !std::is_const< element_type >::value &&std::is_same< typename Container::value_type, value_type >::value, Container >::type *=0)
Construct a span from a container.
iterator begin() const noexcept
Returns a non-const iterator the start of the span.
#define TF_DEV_AXIOM(cond)
The same as TF_AXIOM, but compiled only in dev builds.
TfSpan< const typename Container::value_type > TfMakeConstSpan(const Container &cont)
Helper for constructing a const TfSpan from a container.
TfSpan< typename Container::value_type > TfMakeSpan(Container &cont)
Helper for constructing a non-const TfSpan from a container.