30 #include "pxr/base/tf/api.h"
31 #include "pxr/base/tf/diagnostic.h"
35 #include <type_traits>
38 PXR_NAMESPACE_OPEN_SCOPE
90 using element_type = T;
91 using value_type =
typename std::remove_cv<T>::type;
94 using index_type = std::size_t;
95 using difference_type = std::ptrdiff_t;
98 using const_iterator =
const T*;
99 using reverse_iterator = std::reverse_iterator<iterator>;
100 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
102 TfSpan() noexcept =
default;
108 : _data(ptr), _size(count)
115 :
TfSpan(first, index_type(last-first))
123 template <
class Container>
125 typename std::enable_if<
126 !std::is_const<element_type>::value &&
127 std::is_same<
typename Container::value_type, value_type
130 : _data(cont.
data()), _size(cont.
size())
138 template <
class Container>
140 typename std::enable_if<
141 std::is_same<
typename Container::value_type, value_type
144 : _data(cont.
data()), _size(cont.
size())
150 pointer
data() const noexcept {
return _data; }
153 index_type
size() const noexcept {
return _size; }
156 bool empty() const noexcept {
return _size == 0; }
167 iterator
begin() const noexcept {
return _data; }
170 const_iterator
cbegin() const noexcept {
return _data; }
173 iterator
end() const noexcept {
return _data + _size; }
176 const_iterator
cend() const noexcept {
return _data + _size; }
180 {
return reverse_iterator(
end()); }
183 const_reverse_iterator
crbegin() const noexcept
184 {
return const_reverse_iterator(
cend()); }
187 reverse_iterator
rend() const noexcept
188 {
return reverse_iterator(
begin()); }
191 const_reverse_iterator
crend() const noexcept
192 {
return const_reverse_iterator(
cbegin()); }
199 TF_DEV_AXIOM(offset >= 0 && (index_type)offset < _size);
201 return TfSpan<T>(_data + offset, _size - offset);
204 TF_DEV_AXIOM(((index_type)offset+(index_type)count) <= _size);
210 pointer _data =
nullptr;
211 index_type _size = 0;
216 template <
typename Container>
225 template <
typename Container>
232 PXR_NAMESPACE_CLOSE_SCOPE
#define TF_DEV_AXIOM(cond)
The same as TF_AXIOM, but compiled only in dev builds.
reverse_iterator rbegin() const noexcept
Returns a non-const reverse iterator the start of the span.
TfSpan(pointer first, pointer last)
Construct a span over the range [first, last).
TfSpan(pointer ptr, index_type count)
Construct a span over the range of [ptr, ptr+count).
const_reverse_iterator crbegin() const noexcept
Returns a cons reverse iterator to the start of the span.
iterator end() const noexcept
Returns a non-const iterator to the end of the 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.
iterator begin() const noexcept
Returns a non-const iterator the start of the span.
index_type size() const noexcept
Return the total number of elements in the span.
Represents a range of contiguous elements.
bool empty() const noexcept
Returns true if this span contains no elements, false otherwise.
const_iterator cbegin() const noexcept
Returns a cons iterator to the start of the span.
TfSpan< const typename Container::value_type > TfMakeConstSpan(const Container &cont)
Helper for constructing a const TfSpan from a container.
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.
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.
TfSpan< typename Container::value_type > TfMakeSpan(Container &cont)
Helper for constructing a non-const TfSpan from a container.
reverse_iterator rend() const noexcept
Returns a non-const reverse iterator to the end of the span.
pointer data() const noexcept
Return a pointer to the first element 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.