| 28 | */ |
| 29 | template <class T> |
| 30 | class TArrayRef { |
| 31 | public: |
| 32 | using iterator = T*; |
| 33 | using const_iterator = const T*; |
| 34 | using reference = T&; |
| 35 | using const_reference = const T&; |
| 36 | using value_type = T; |
| 37 | using reverse_iterator = std::reverse_iterator<iterator>; |
| 38 | using const_reverse_iterator = std::reverse_iterator<const_iterator>; |
| 39 | |
| 40 | constexpr inline TArrayRef() noexcept |
| 41 | : T_(nullptr) |
| 42 | , S_(0) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | constexpr inline TArrayRef(T* data Y_LIFETIME_BOUND, size_t len) noexcept |
| 47 | : T_(data) |
| 48 | , S_(len) |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | template <class TT, typename = std::enable_if_t<std::is_convertible_v<TT*, T*>>> |
| 53 | constexpr inline TArrayRef(TT* data Y_LIFETIME_BOUND, size_t len) noexcept |
| 54 | : TArrayRef(static_cast<T*>(data), len) |
| 55 | { |
| 56 | static_assert( |
| 57 | sizeof(TT) == sizeof(T), |
| 58 | "Attempt to create TArrayRef from an array of elements of a derived class with a different size"); |
| 59 | } |
| 60 | |
| 61 | constexpr inline TArrayRef(T* begin Y_LIFETIME_BOUND, T* end Y_LIFETIME_BOUND) noexcept |
| 62 | : T_(begin) |
| 63 | , S_(NonNegativeDistance(begin, end)) |
| 64 | { |
| 65 | } |
| 66 | |
| 67 | template <class TT, typename = std::enable_if_t<std::is_convertible_v<TT*, T*>>> |
| 68 | constexpr inline TArrayRef(TT* begin Y_LIFETIME_BOUND, TT* end Y_LIFETIME_BOUND) noexcept |
| 69 | : TArrayRef(begin, NonNegativeDistance(begin, end)) |
| 70 | { |
| 71 | } |
| 72 | |
| 73 | constexpr inline TArrayRef(std::initializer_list<T> list Y_LIFETIME_BOUND) noexcept |
| 74 | : T_(list.begin()) |
| 75 | , S_(list.size()) |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | template <class Container, typename = std::enable_if_t<std::is_convertible_v<decltype(std::declval<Container>().data()), T*>>> |
| 80 | constexpr inline TArrayRef(Container&& container) noexcept |
| 81 | : TArrayRef(container.data(), container.size()) |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | template <size_t N> |
| 86 | constexpr inline TArrayRef(T (&array Y_LIFETIME_BOUND)[N]) noexcept |
| 87 | : T_(array) |