24 #ifndef PXR_BASE_TF_SPAN_H 25 #define PXR_BASE_TF_SPAN_H 30 #include "pxr/base/tf/api.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)
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; }
179 iterator
begin() const noexcept {
return _data; }
182 const_iterator
cbegin() const noexcept {
return _data; }
185 iterator
end() const noexcept {
return _data + _size; }
188 const_iterator
cend() const noexcept {
return _data + _size; }
192 {
return reverse_iterator(
end()); }
195 const_reverse_iterator
crbegin() const noexcept
196 {
return const_reverse_iterator(
cend()); }
199 reverse_iterator
rend() const noexcept
200 {
return reverse_iterator(
begin()); }
203 const_reverse_iterator
crend() const noexcept
204 {
return const_reverse_iterator(
cbegin()); }
211 TF_DEV_AXIOM(offset >= 0 && (index_type)offset < _size);
213 return TfSpan<T>(_data + offset, _size - offset);
216 TF_DEV_AXIOM(((index_type)offset+(index_type)count) <= _size);
233 pointer _data =
nullptr;
234 index_type _size = 0;
239 template <
typename Container>
248 template <
typename Container>
255 PXR_NAMESPACE_CLOSE_SCOPE
257 #endif // PXR_BASE_TF_SPAN_H #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).
reference operator[](index_type idx) const
Returns a reference to the idx'th element of the span.
TfSpan< T > last(size_t count) const
Return a subspan consisting of the last count elements of this span.
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.
TfSpan< T > first(size_t count) const
Return a subspan consisting of the first count elements of this span.
iterator end() const noexcept
Returns a non-const 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.
Low-level utilities for informing users of various internal and external diagnostic conditions.
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.
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.
reference front() const
Return a reference to the first element in the span.
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.