1132720Skan//===----------------------- adt.h - Handy ADTs -----------------*- C++ -*-===// 2132720Skan// 3132720Skan// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4132720Skan// See https://llvm.org/LICENSE.txt for license information. 5132720Skan// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6132720Skan// 7132720Skan//===----------------------------------------------------------------------===// 8132720Skan// 9132720Skan// This file is a part of the ORC runtime support library. 10132720Skan// 11132720Skan//===----------------------------------------------------------------------===// 12132720Skan 13132720Skan#ifndef ORC_RT_ADT_H 14132720Skan#define ORC_RT_ADT_H 15132720Skan 16132720Skan#include <cstring> 17132720Skan#include <limits> 18169691Skan#include <ostream> 19132720Skan#include <string> 20132720Skan 21132720Skannamespace __orc_rt { 22132720Skan 23132720Skanconstexpr std::size_t dynamic_extent = std::numeric_limits<std::size_t>::max(); 24132720Skan 25132720Skan/// A substitute for std::span (and llvm::ArrayRef). 26132720Skan/// FIXME: Remove in favor of std::span once we can use c++20. 27132720Skantemplate <typename T, std::size_t Extent = dynamic_extent> class span { 28132720Skanpublic: 29132720Skan typedef T element_type; 30132720Skan typedef std::remove_cv<T> value_type; 31132720Skan typedef std::size_t size_type; 32132720Skan typedef std::ptrdiff_t difference_type; 33132720Skan typedef T *pointer; 34132720Skan typedef const T *const_pointer; 35132720Skan typedef T &reference; 36132720Skan typedef const T &const_reference; 37 38 typedef pointer iterator; 39 40 static constexpr std::size_t extent = Extent; 41 42 constexpr span() noexcept = default; 43 constexpr span(T *first, size_type count) noexcept 44 : Data(first), Size(count) {} 45 46 template <std::size_t N> 47 constexpr span(T (&arr)[N]) noexcept : Data(&arr[0]), Size(N) {} 48 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; } 55 56private: 57 T *Data = nullptr; 58 size_type Size = 0; 59}; 60 61} // end namespace __orc_rt 62 63#endif // ORC_RT_ADT_H 64