llvm/llvm/include/llvm/ADT/ArrayRef.h

//===- ArrayRef.h - Array Reference Wrapper ---------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_ADT_ARRAYREF_H
#define LLVM_ADT_ARRAYREF_H

#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Compiler.h"
#include <algorithm>
#include <array>
#include <cassert>
#include <cstddef>
#include <initializer_list>
#include <iterator>
#include <memory>
#include <type_traits>
#include <vector>

namespace llvm {
  template<typename T> class [[nodiscard]] MutableArrayRef;

  /// ArrayRef - Represent a constant reference to an array (0 or more elements
  /// consecutively in memory), i.e. a start pointer and a length.  It allows
  /// various APIs to take consecutive elements easily and conveniently.
  ///
  /// This class does not own the underlying data, it is expected to be used in
  /// situations where the data resides in some other buffer, whose lifetime
  /// extends past that of the ArrayRef. For this reason, it is not in general
  /// safe to store an ArrayRef.
  ///
  /// This is intended to be trivially copyable, so it should be passed by
  /// value.
  template<typename T>
  class LLVM_GSL_POINTER [[nodiscard]] ArrayRef {};

  /// MutableArrayRef - Represent a mutable reference to an array (0 or more
  /// elements consecutively in memory), i.e. a start pointer and a length.  It
  /// allows various APIs to take and modify consecutive elements easily and
  /// conveniently.
  ///
  /// This class does not own the underlying data, it is expected to be used in
  /// situations where the data resides in some other buffer, whose lifetime
  /// extends past that of the MutableArrayRef. For this reason, it is not in
  /// general safe to store a MutableArrayRef.
  ///
  /// This is intended to be trivially copyable, so it should be passed by
  /// value.
  template<typename T>
  class [[nodiscard]] MutableArrayRef : public ArrayRef<T> {};

  /// This is a MutableArrayRef that owns its array.
  template <typename T> class OwningArrayRef : public MutableArrayRef<T> {};

  /// @name ArrayRef Deduction guides
  /// @{
  /// Deduction guide to construct an ArrayRef from a single element.
  template <typename T> ArrayRef(const T &OneElt) -> ArrayRef<T>;

  /// Deduction guide to construct an ArrayRef from a pointer and length
  template <typename T> ArrayRef(const T *data, size_t length) -> ArrayRef<T>;

  /// Deduction guide to construct an ArrayRef from a range
  template <typename T> ArrayRef(const T *data, const T *end) -> ArrayRef<T>;

  /// Deduction guide to construct an ArrayRef from a SmallVector
  template <typename T> ArrayRef(const SmallVectorImpl<T> &Vec) -> ArrayRef<T>;

  /// Deduction guide to construct an ArrayRef from a SmallVector
  template <typename T, unsigned N>
  ArrayRef(const SmallVector<T, N> &Vec) -> ArrayRef<T>;

  /// Deduction guide to construct an ArrayRef from a std::vector
  template <typename T> ArrayRef(const std::vector<T> &Vec) -> ArrayRef<T>;

  /// Deduction guide to construct an ArrayRef from a std::array
  template <typename T, std::size_t N>
  ArrayRef(const std::array<T, N> &Vec) -> ArrayRef<T>;

  /// Deduction guide to construct an ArrayRef from an ArrayRef (const)
  template <typename T> ArrayRef(const ArrayRef<T> &Vec) -> ArrayRef<T>;

  /// Deduction guide to construct an ArrayRef from an ArrayRef
  template <typename T> ArrayRef(ArrayRef<T> &Vec) -> ArrayRef<T>;

  /// Deduction guide to construct an ArrayRef from a C array.
  template <typename T, size_t N> ArrayRef(const T (&Arr)[N]) -> ArrayRef<T>;

  /// @}

  /// @name MutableArrayRef Deduction guides
  /// @{
  /// Deduction guide to construct a `MutableArrayRef` from a single element
  template <class T> MutableArrayRef(T &OneElt) -> MutableArrayRef<T>;

  /// Deduction guide to construct a `MutableArrayRef` from a pointer and
  /// length.
  template <class T>
  MutableArrayRef(T *data, size_t length) -> MutableArrayRef<T>;

  /// Deduction guide to construct a `MutableArrayRef` from a `SmallVector`.
  template <class T>
  MutableArrayRef(SmallVectorImpl<T> &Vec) -> MutableArrayRef<T>;

  template <class T, unsigned N>
  MutableArrayRef(SmallVector<T, N> &Vec) -> MutableArrayRef<T>;

  /// Deduction guide to construct a `MutableArrayRef` from a `std::vector`.
  template <class T> MutableArrayRef(std::vector<T> &Vec) -> MutableArrayRef<T>;

  /// Deduction guide to construct a `MutableArrayRef` from a `std::array`.
  template <class T, std::size_t N>
  MutableArrayRef(std::array<T, N> &Vec) -> MutableArrayRef<T>;

  /// Deduction guide to construct a `MutableArrayRef` from a C array.
  template <typename T, size_t N>
  MutableArrayRef(T (&Arr)[N]) -> MutableArrayRef<T>;

  /// @}
  /// @name ArrayRef Comparison Operators
  /// @{

  template<typename T>
  inline bool operator==(ArrayRef<T> LHS, ArrayRef<T> RHS) {}

  template <typename T>
  inline bool operator==(SmallVectorImpl<T> &LHS, ArrayRef<T> RHS) {}

  template <typename T>
  inline bool operator!=(ArrayRef<T> LHS, ArrayRef<T> RHS) {}

  template <typename T>
  inline bool operator!=(SmallVectorImpl<T> &LHS, ArrayRef<T> RHS) {}

  /// @}

  template <typename T> hash_code hash_value(ArrayRef<T> S) {}

  // Provide DenseMapInfo for ArrayRefs.
  DenseMapInfo<ArrayRef<T>, void>;

} // end namespace llvm

#endif // LLVM_ADT_ARRAYREF_H