1 //===----------------------- adt.h - Handy ADTs -----------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of the ORC runtime support library.
11 //===----------------------------------------------------------------------===//
23 constexpr std::size_t dynamic_extent
= std::numeric_limits
<std::size_t>::max();
25 /// A substitute for std::span (and llvm::ArrayRef).
26 /// FIXME: Remove in favor of std::span once we can use c++20.
27 template <typename T
, std::size_t Extent
= dynamic_extent
> class span
{
29 typedef T element_type
;
30 typedef std::remove_cv
<T
> value_type
;
31 typedef std::size_t size_type
;
32 typedef std::ptrdiff_t difference_type
;
34 typedef const T
*const_pointer
;
36 typedef const T
&const_reference
;
38 typedef pointer iterator
;
40 static constexpr std::size_t extent
= Extent
;
42 constexpr span() noexcept
= default;
43 constexpr span(T
*first
, size_type count
) noexcept
44 : Data(first
), Size(count
) {}
46 template <std::size_t N
>
47 constexpr span(T (&arr
)[N
]) noexcept
: Data(&arr
[0]), Size(N
) {}
49 constexpr iterator
begin() const noexcept
{ return Data
; }
50 constexpr iterator
end() const noexcept
{ return Data
+ Size
; }
51 constexpr pointer
data() const noexcept
{ return Data
; }
52 constexpr reference
operator[](size_type idx
) const { return Data
[idx
]; }
53 constexpr size_type
size() const noexcept
{ return Size
; }
54 constexpr bool empty() const noexcept
{ return Size
== 0; }
61 } // end namespace __orc_rt
63 #endif // ORC_RT_ADT_H