17 #ifndef TCB_SPAN_NAMESPACE_NAME
18 #define TCB_SPAN_NAMESPACE_NAME UT::tcb
35 #ifndef TCB_SPAN_HPP_INCLUDED
36 #define TCB_SPAN_HPP_INCLUDED
41 #include <type_traits>
43 #ifndef TCB_SPAN_NO_EXCEPTIONS
45 #if !(defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND))
46 #define TCB_SPAN_NO_EXCEPTIONS
50 #ifndef TCB_SPAN_NO_EXCEPTIONS
57 #ifndef TCB_SPAN_NAMESPACE_NAME
58 #define TCB_SPAN_NAMESPACE_NAME tcb
61 #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
62 #define TCB_SPAN_HAVE_CPP17
65 #if __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
66 #define TCB_SPAN_HAVE_CPP14
72 #if !defined(TCB_SPAN_THROW_ON_CONTRACT_VIOLATION) && \
73 !defined(TCB_SPAN_TERMINATE_ON_CONTRACT_VIOLATION) && \
74 !defined(TCB_SPAN_NO_CONTRACT_CHECKING)
75 #if defined(NDEBUG) || !defined(TCB_SPAN_HAVE_CPP14)
76 #define TCB_SPAN_NO_CONTRACT_CHECKING
78 #define TCB_SPAN_TERMINATE_ON_CONTRACT_VIOLATION
82 #if defined(TCB_SPAN_THROW_ON_CONTRACT_VIOLATION)
83 struct contract_violation_error : std::logic_error {
84 explicit contract_violation_error(
const char* msg) : std::logic_error(msg)
88 inline void contract_violation(
const char* msg)
90 throw contract_violation_error(msg);
93 #elif defined(TCB_SPAN_TERMINATE_ON_CONTRACT_VIOLATION)
94 [[noreturn]]
inline void contract_violation(
const char* )
101 #if !defined(TCB_SPAN_NO_CONTRACT_CHECKING)
102 #define TCB_SPAN_STRINGIFY(cond) #cond
103 #define TCB_SPAN_EXPECT(cond) \
104 cond ? (void) 0 : contract_violation("Expected " TCB_SPAN_STRINGIFY(cond))
106 #define TCB_SPAN_EXPECT(cond)
109 #define TCB_SPAN_EXPECT(cond) UT_ASSERT(cond)
112 #if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_inline_variables)
113 #define TCB_SPAN_INLINE_VAR inline
115 #define TCB_SPAN_INLINE_VAR
118 #if defined(TCB_SPAN_HAVE_CPP14) || \
119 (defined(__cpp_constexpr) && __cpp_constexpr >= 201304)
120 #define TCB_SPAN_HAVE_CPP14_CONSTEXPR
123 #if defined(TCB_SPAN_HAVE_CPP14_CONSTEXPR)
124 #define TCB_SPAN_CONSTEXPR14 constexpr
126 #define TCB_SPAN_CONSTEXPR14
129 #if defined(TCB_SPAN_HAVE_CPP14_CONSTEXPR) && \
130 (!defined(_MSC_VER) || _MSC_VER > 1900)
131 #define TCB_SPAN_CONSTEXPR_ASSIGN constexpr
133 #define TCB_SPAN_CONSTEXPR_ASSIGN
136 #if defined(TCB_SPAN_NO_CONTRACT_CHECKING)
137 #define TCB_SPAN_CONSTEXPR11 constexpr
139 #define TCB_SPAN_CONSTEXPR11 TCB_SPAN_CONSTEXPR14
142 #if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_deduction_guides)
143 #define TCB_SPAN_HAVE_DEDUCTION_GUIDES
146 #if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_lib_byte)
147 #define TCB_SPAN_HAVE_STD_BYTE
150 #if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_lib_array_constexpr)
151 #define TCB_SPAN_HAVE_CONSTEXPR_STD_ARRAY_ETC
154 #if defined(TCB_SPAN_HAVE_CONSTEXPR_STD_ARRAY_ETC)
155 #define TCB_SPAN_ARRAY_CONSTEXPR constexpr
157 #define TCB_SPAN_ARRAY_CONSTEXPR
160 #ifdef TCB_SPAN_HAVE_STD_BYTE
166 #if defined(TCB_SPAN_HAVE_CPP17)
167 #define TCB_SPAN_NODISCARD [[nodiscard]]
169 #define TCB_SPAN_NODISCARD
174 template <
typename ElementType, std::
size_t Extent = dynamic_extent>
179 template <
typename E, std::
size_t S>
188 static constexpr std::size_t
size =
S;
191 template <
typename E>
204 #if defined(TCB_SPAN_HAVE_CPP17) || \
205 defined(__cpp_lib_nonmember_container_access)
210 constexpr
auto size(
const C&
c) -> decltype(
c.size())
215 template <
class T, std::
size_t N>
216 constexpr std::size_t
size(
const T (&)[
N]) noexcept
222 constexpr
auto data(C&
c) -> decltype(
c.data())
228 constexpr
auto data(
const C&
c) -> decltype(
c.data())
233 template <
class T, std::
size_t N>
234 constexpr
T*
data(T (&array)[
N]) noexcept
240 constexpr
const E*
data(std::initializer_list<E> il) noexcept
244 #endif // TCB_SPAN_HAVE_CPP17
246 #if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_lib_void_t)
249 template <
typename...>
253 template <
typename T>
260 template <
typename T, std::
size_t S>
266 template <
typename T, std::
size_t N>
269 template <
typename,
typename =
void>
272 template <
typename T>
274 decltype(detail::data(std::declval<T>()))>>
277 template <
typename C,
typename U = uncvref_t<C>>
284 template <
typename T>
287 template <
typename,
typename,
typename =
void>
290 template <
typename T,
typename E>
293 typename std::enable_if<
295 typename std::remove_cv<decltype(detail::data(std::declval<T>()))>::type,
298 remove_pointer_t<decltype(detail::data(std::declval<T>()))> (*)[],
303 template <
typename,
typename =
size_t>
306 template <
typename T>
311 template <
typename ElementType, std::
size_t Extent>
314 "A span's ElementType must be an object type (not a "
315 "reference type or void)");
317 "A span's ElementType must be a complete type (not a forward "
320 "A span's ElementType cannot be an abstract class type");
341 std::size_t E = Extent,
347 : storage_(ptr, count)
353 : storage_(first_elem, last_elem - first_elem)
356 last_elem - first_elem ==
357 static_cast<std::ptrdiff_t>(
extent));
360 template <std::size_t
N, std::size_t E = Extent,
361 typename std::enable_if<
369 template <
typename T, std::size_t
N, std::size_t E = Extent,
370 typename std::enable_if<
373 std::array<T, N>&, ElementType>::
value,
376 : storage_(arr.data(),
N)
379 template <
typename T, std::size_t
N, std::size_t E = Extent,
380 typename std::enable_if<
383 const std::array<T, N>&, ElementType>::
value,
386 : storage_(arr.data(),
N)
390 typename Container, std::size_t E = Extent,
391 typename std::enable_if<
394 Container&, ElementType>
::value,
396 constexpr
span(Container& cont)
397 : storage_(detail::
data(cont), detail::
size(cont))
401 typename Container, std::size_t E = Extent,
402 typename std::enable_if<
405 const Container&, ElementType>
::value,
407 constexpr
span(
const Container& cont)
408 : storage_(detail::
data(cont), detail::
size(cont))
411 constexpr
span(
const span& other) noexcept =
default;
413 template <
typename OtherElementType, std::size_t OtherExtent,
414 typename std::enable_if<
416 Extent == OtherExtent) &&
417 std::is_convertible<OtherElementType (*)[],
421 : storage_(other.data(), other.size())
424 ~span() noexcept = default;
427 operator=(const
span& other) noexcept = default;
430 template <std::
size_t Count>
437 template <std::
size_t Count>
444 template <std::
size_t Offset, std::
size_t Count = dynamic_extent>
451 template <std::
size_t Offset, std::
size_t Count = dynamic_extent>
456 return {
data() + Offset,
464 return {
data(), count};
471 return {
data() + (
size() - count), count};
500 return *(
data() + idx);
533 storage_type storage_{};
536 #ifdef TCB_SPAN_HAVE_DEDUCTION_GUIDES
539 template <
class T,
size_t N>
542 template <
class T,
size_t N>
543 span(std::array<T, N>&)->span<
T, N>;
545 template <
class T,
size_t N>
546 span(
const std::array<T, N>&)->span<
const T, N>;
548 template <
class Container>
549 span(Container&)->span<
typename std::remove_reference<
552 template <
class Container>
555 #endif // TCB_HAVE_DEDUCTION_GUIDES
557 template <
typename ElementType, std::
size_t Extent>
564 template <
typename T, std::
size_t N>
570 template <
typename T, std::
size_t N>
576 template <
typename T, std::
size_t N>
583 template <
typename Container>
584 constexpr
span<
typename std::remove_reference<
585 decltype(*
detail::data(std::declval<Container&>()))>::type>
591 template <
typename Container>
598 template <
typename ElementType, std::
size_t Extent>
600 :
sizeof(ElementType) * Extent)>
607 class ElementType,
size_t Extent,
610 :
sizeof(ElementType) * Extent)>
616 template <std::
size_t N,
typename E, std::
size_t S>
627 #pragma clang diagnostic push
628 #pragma clang diagnostic ignored "-Wmismatched-tags"
631 template <
typename ElementType,
size_t Extent>
633 :
public integral_constant<size_t, Extent> {};
635 template <
typename ElementType>
637 ElementType, TCB_SPAN_NAMESPACE_NAME::dynamic_extent>>;
639 template <size_t I, typename ElementType, size_t Extent>
640 class tuple_element<I, TCB_SPAN_NAMESPACE_NAME::span<ElementType, Extent>> {
649 #pragma clang diagnostic pop
654 #endif // TCB_SPAN_HPP_INCLUDED
660 template <
typename ElementType,
670 template <
typename ElementType,
687 template <
typename ElementType,
702 template <
typename SPANL,
typename SPANR>
709 template <
typename SPANL,
typename SPANR>
constexpr size_t size(const OIIO::span< T, E > &c)
constexpr span< ElementType, Extent > make_span(span< ElementType, Extent > s) noexcept
TCB_SPAN_CONSTEXPR11 span(pointer ptr, size_type count)
typename std::remove_pointer< T >::type remove_pointer_t
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
static constexpr std::size_t size
TCB_SPAN_CONSTEXPR11 reference back() const
constexpr bool UTdeepEqual(const SPANL &left, const SPANR &right)
GLsizei const GLfloat * value
span< byte,((Extent==dynamic_extent)?dynamic_extent:sizeof(ElementType)*Extent)> as_writable_bytes(span< ElementType, Extent > s) noexcept
constexpr span_storage() noexcept=default
constexpr pointer data() const noexcept
constexpr span_storage(E *p_ptr, std::size_t) noexcept
TCB_SPAN_NODISCARD constexpr bool empty() const noexcept
const element_type * const_pointer
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
typename std::remove_cv< ElementType >::type value_type
constexpr const E * data(std::initializer_list< E > il) noexcept
span< const byte,((Extent==dynamic_extent)?dynamic_extent:sizeof(ElementType)*Extent)> as_bytes(span< ElementType, Extent > s) noexcept
std::ptrdiff_t difference_type
static constexpr size_type extent
TCB_SPAN_CONSTEXPR11 span< element_type, Count > last() const
TCB_SPAN_CONSTEXPR11 span< element_type, dynamic_extent > last(size_type count) const
constexpr size_type size() const noexcept
TCB_SPAN_ARRAY_CONSTEXPR reverse_iterator rbegin() const noexcept
TCB_SPAN_ARRAY_CONSTEXPR span(const std::array< T, N > &arr) noexcept
constexpr auto data(C &c) -> decltype(c.data())
constexpr iterator begin() const noexcept
TCB_SPAN_INLINE_VAR constexpr std::size_t dynamic_extent
constexpr iterator end() const noexcept
TCB_SPAN_ARRAY_CONSTEXPR span(std::array< T, N > &arr) noexcept
#define TCB_SPAN_INLINE_VAR
#define TCB_SPAN_CONSTEXPR11
#define TCB_SPAN_ARRAY_CONSTEXPR
#define TCB_SPAN_NODISCARD
constexpr span(const span< OtherElementType, OtherExtent > &other) noexcept
typename std::remove_cv< typename std::remove_reference< T >::type >::type uncvref_t
#define TCB_SPAN_CONSTEXPR_ASSIGN
constexpr size_type size_bytes() const noexcept
constexpr span(element_type(&arr)[N]) noexcept
constexpr bool UTshallowEqual(const SPANL &left, const SPANR &right)
TCB_SPAN_CONSTEXPR11 reference front() const
TCB_SPAN_ARRAY_CONSTEXPR reverse_iterator rend() const noexcept
TCB_SPAN_CONSTEXPR11 span< element_type, dynamic_extent > subspan(size_type offset, size_type count=dynamic_extent) const
TCB_SPAN_CONSTEXPR11 subspan_return_t< Offset, Count > subspan() const
TCB_SPAN_CONSTEXPR11 span< element_type, dynamic_extent > first(size_type count) const
GA_API const UT_StringHolder N
constexpr auto size(const C &c) -> decltype(c.size())
constexpr span_storage(E *p_ptr, std::size_t p_size) noexcept
#define TCB_SPAN_EXPECT(cond)
constexpr span() noexcept
constexpr span(Container &cont)
constexpr span(const Container &cont)
TCB_SPAN_CONSTEXPR11 reference operator[](size_type idx) const
TCB_SPAN_CONSTEXPR11 span(pointer first_elem, pointer last_elem)
std::reverse_iterator< iterator > reverse_iterator
constexpr bool operator()(const SPANL &left, const SPANR &right) const
constexpr bool operator()(const SPANL &left, const SPANR &right) const
#define TCB_SPAN_NAMESPACE_NAME
const element_type & const_reference