Path: blob/main/contrib/llvm-project/compiler-rt/lib/orc/adt.h
39566 views
//===----------------------- adt.h - Handy ADTs -----------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of the ORC runtime support library.9//10//===----------------------------------------------------------------------===//1112#ifndef ORC_RT_ADT_H13#define ORC_RT_ADT_H1415#include <cstring>16#include <limits>17#include <ostream>18#include <string>1920namespace __orc_rt {2122constexpr std::size_t dynamic_extent = std::numeric_limits<std::size_t>::max();2324/// A substitute for std::span (and llvm::ArrayRef).25/// FIXME: Remove in favor of std::span once we can use c++20.26template <typename T, std::size_t Extent = dynamic_extent> class span {27public:28typedef T element_type;29typedef std::remove_cv<T> value_type;30typedef std::size_t size_type;31typedef std::ptrdiff_t difference_type;32typedef T *pointer;33typedef const T *const_pointer;34typedef T &reference;35typedef const T &const_reference;3637typedef pointer iterator;3839static constexpr std::size_t extent = Extent;4041constexpr span() noexcept = default;42constexpr span(T *first, size_type count) noexcept43: Data(first), Size(count) {}4445template <std::size_t N>46constexpr span(T (&arr)[N]) noexcept : Data(&arr[0]), Size(N) {}4748constexpr iterator begin() const noexcept { return Data; }49constexpr iterator end() const noexcept { return Data + Size; }50constexpr pointer data() const noexcept { return Data; }51constexpr reference operator[](size_type idx) const { return Data[idx]; }52constexpr size_type size() const noexcept { return Size; }53constexpr bool empty() const noexcept { return Size == 0; }5455private:56T *Data = nullptr;57size_type Size = 0;58};5960} // end namespace __orc_rt6162#endif // ORC_RT_ADT_H636465