<commit_before>/******************************************************************************
 *                    _   _____   __________                                  *
 *                   | | / / _ | / __/_  __/     Visibility                   *
 *                   | |/ / __ |_\ \  / /          Across                     *
 *                   |___/_/ |_/___/ /_/       Space and Time                 *
 *                                                                            *
 * This file is part of VAST. It is subject to the license terms in the       *
 * LICENSE file found in the top-level directory of this distribution and at  *
 * http://vast.io/license. No part of VAST, including this file, may be       *
 * copied, modified, propagated, or distributed except according to the terms *
 * contained in the LICENSE file.                                             *
 ******************************************************************************/

// This file comes from a 3rd party and has been adapted to fit into the VAST
// code base. Details about the original file:
//
// - Repository: https://github.com/Microsoft/GSL
// - Commit:     <PASSWORD>
// - Path:       GSL/include/gsl/span
// - Author:     Microsoft
// - Copyright:  (c) 2015 Microsoft Corporation. All rights reserved.
// - License:    MIT

#pragma once

#include <algorithm>
#include <array>
#include <cstddef>
#include <iterator>
#include <limits>
#include <stdexcept>
#include <type_traits>
#include <utility>

#include "vast/byte.hpp"
#include "vast/detail/assert.hpp"
#include "vast/detail/narrow.hpp"

namespace vast {

// [views.constants], constants
inline constexpr size_t dynamic_extent = std::numeric_limits<size_t>::max();

template <class ElementType, size_t Extent = dynamic_extent>
class span;

namespace detail {

template <class T>
struct is_span_oracle : std::false_type {};

template <class ElementType, size_t Extent>
struct is_span_oracle<span<ElementType, Extent>> : std::true_type {};

template <class T>
constexpr auto is_span_oracle_v = is_span_oracle<T>::value;

template <class T>
struct is_span : public is_span_oracle<std::remove_cv_t<T>> {};

template <class T>
constexpr auto is_span_v = is_span<T>::value;

template <class T>
struct is_std_array_oracle : std::false_type {};

template <class ElementType, std::size_t Extent>
struct is_std_array_oracle<std::array<ElementType, Extent>> : std::true_type {};

template <class T>
struct is_std_array : public is_std_array_oracle<std::remove_cv_t<T>> {};

template <class T>
constexpr auto is_std_array_v = is_std_array<T>::value;

template <size_t From, size_t To>
struct is_allowed_extent_conversion
  : public std::integral_constant<bool, From == To || From == dynamic_extent
                                          || To == dynamic_extent> {};

template <size_t From, size_t To>
constexpr auto is_allowed_extent_conversion_v = is_allowed_extent_conversion<
  From, To>::value;

template <class From, class To>
struct is_allowed_element_type_conversion
  : public std::integral_constant<bool,
                                  std::is_convertible_v<From (*)[], To (*)[]>> {
};

template <class Span, bool IsConst>
class span_iterator {
  using element_type_ = typename Span::element_type;

public:
  using iterator_category = std::random_access_iterator_tag;
  using value_type = std::remove_cv_t<element_type_>;
  using difference_type = typename Span::index_type;

  using reference = std::conditional_t<IsConst, const element_type_,
                                       element_type_>&;
  using pointer = std::add_pointer_t<reference>;

  span_iterator() = default;

  constexpr span_iterator(const Span* span,
                          typename Span::index_type idx) noexcept
    : span_(span), index_(idx) {
  }

  friend span_iterator<Span, true>;

  template <bool B, std::enable_if_t<!B && IsConst>* = nullptr>
  constexpr span_iterator(const span_iterator<Span, B>& other) noexcept
    : span_iterator(other.span_, other.index_) {
  }

  constexpr reference operator*() const {
    return *(span_->data() + index_);
  }

  constexpr pointer operator->() const {
    return span_->data() + index_;
  }

  constexpr span_iterator& operator++() {
    ++index_;
    return *this;
  }

  constexpr span_iterator operator++(int) {
    auto ret = *this;
    ++(*this);
    return ret;
  }

  constexpr span_iterator& operator--() {
    --index_;
    return *this;
  }

  constexpr span_iterator operator--(int) {
    auto ret = *this;
    --(*this);
    return ret;
  }

  constexpr span_iterator operator+(difference_type n) const {
    auto ret = *this;
    return ret += n;
  }

  constexpr span_iterator& operator+=(difference_type n) {
    index_ += n;
    return *this;
  }

  constexpr span_iterator operator-(difference_type n) const {
    auto ret = *this;
    return ret -= n;
  }

  constexpr span_iterator& operator-=(difference_type n) {
    return *this += -n;
  }

  constexpr difference_type operator-(span_iterator rhs) const {
    return index_ - rhs.index_;
  }

  constexpr reference operator[](difference_type n) const {
    return *(*this + n);
  }

  constexpr friend bool operator==(span_iterator lhs,
                                   span_iterator rhs) noexcept {
    return lhs.span_ == rhs.span_ && lhs.index_ == rhs.index_;
  }

  constexpr friend bool operator!=(span_iterator lhs,
                                   span_iterator rhs) noexcept {
    return !(lhs == rhs);
  }

  constexpr friend bool operator<(span_iterator lhs,
                                  span_iterator rhs) noexcept {
    return lhs.index_ < rhs.index_;
  }

  constexpr friend bool operator<=(span_iterator lhs,
                                   span_iterator rhs) noexcept {
    return !(rhs < lhs);
  }

  constexpr friend bool operator>(span_iterator lhs,
                                  span_iterator rhs) noexcept {
    return rhs < lhs;
  }

  constexpr friend bool operator>=(span_iterator lhs,
                                   span_iterator rhs) noexcept {
    return !(rhs > lhs);
  }

protected:
  const Span* span_ = nullptr;
  size_t index_ = 0;
};

template <class Span, bool IsConst>
constexpr span_iterator<Span, IsConst>
operator+(typename span_iterator<Span, IsConst>::difference_type n,
          span_iterator<Span, IsConst> rhs) {
  return rhs + n;
}

template <class Span, bool IsConst>
constexpr span_iterator<Span, IsConst>
operator-(typename span_iterator<Span, IsConst>::difference_type n,
          span_iterator<Span, IsConst> rhs) {
  return rhs - n;
}

template <size_t Ext>
class extent_type {
public:
  using index_type = size_t;

  static_assert(Ext >= 0, "A fixed-size span must be >= 0 in size.");

  constexpr extent_type() noexcept {
  }

  template <index_type Other>
  constexpr extent_type(extent_type<Other>) {
    static_assert(Other == Ext || Other == dynamic_extent,
                  "Mismatch between fixed-size extent and size of initializing "
                  "data.");
  }

  constexpr extent_type(index_type) {
    // nop
  }

  constexpr index_type size() const noexcept {
    return Ext;
  }
};

template <>
class extent_type<dynamic_extent> {
public:
  using index_type = size_t;

  template <index_type Other>
  explicit constexpr extent_type(extent_type<Other> ext) : size_(ext.size()) {
  }

  explicit constexpr extent_type(index_type size) : size_(size) {
    // nop
  }

  constexpr index_type size() const noexcept {
    return size_;
  }

private:
  index_type size_;
};

template <class ElementType, size_t Extent, size_t Offset, size_t Count>
struct calculate_subspan_type {
  using type = span<ElementType,
                    Count != dynamic_extent
                      ? Count
                      : (Extent != dynamic_extent ? Extent - Offset : Extent)>;
};

} // namespace detail

// [span], class template span
template <class ElementType, size_t Extent>
class span {
public:
  // constants and types
  using element_type = ElementType;
  using value_type = std::remove_cv_t<ElementType>;
  using index_type = size_t;
  using pointer = element_type*;
  using reference = element_type&;

  using iterator = detail::span_iterator<span<ElementType, Extent>, false>;
  using const_iterator = detail::span_iterator<span<ElementType, Extent>, true>;
  using reverse_iterator = std::reverse_iterator<iterator>;
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;

  using size_type = index_type;

  static constexpr index_type extent{Extent};

  // [span.cons], span constructors, copy, assignment, and destructor
  template <bool Dependent = false,
            // "Dependent" is needed to make "std::enable_if_t<Dependent ||
            // Extent <= 0>" SFINAE, since "std::enable_if_t<Extent <= 0>" is
            // ill-formed when Extent is greater than 0.
            class = std::enable_if_t<(Dependent || Extent <= 0)>>
  constexpr span() noexcept : storage_(nullptr, detail::extent_type<0>()) {
  }<commit_msg>Fix SFINAE expression<commit_after>/******************************************************************************
 *                    _   _____   __________                                  *
 *                   | | / / _ | / __/_  __/     Visibility                   *
 *                   | |/ / __ |_\ \  / /          Across                     *
 *                   |___/_/ |_/___/ /_/       Space and Time                 *
 *                                                                            *
 * This file is part of VAST. It is subject to the license terms in the       *
 * LICENSE file found in the top-level directory of this distribution and at  *
 * http://vast.io/license. No part of VAST, including this file, may be       *
 * copied, modified, propagated, or distributed except according to the terms *
 * contained in the LICENSE file.                                             *
 ******************************************************************************/

// This file comes from a 3rd party and has been adapted to fit into the VAST
// code base. Details about the original file:
//
// - Repository: https://github.com/Microsoft/GSL
// - Commit:     <PASSWORD>
// - Path:       GSL/include/gsl/span
// - Author:     Microsoft
// - Copyright:  (c) 2015 Microsoft Corporation. All rights reserved.
// - License:    MIT

#pragma once

#include <algorithm>
#include <array>
#include <cstddef>
#include <iterator>
#include <limits>
#include <stdexcept>
#include <type_traits>
#include <utility>

#include "vast/byte.hpp"
#include "vast/detail/assert.hpp"
#include "vast/detail/narrow.hpp"

namespace vast {

// [views.constants], constants
inline constexpr size_t dynamic_extent = std::numeric_limits<size_t>::max();

template <class ElementType, size_t Extent = dynamic_extent>
class span;

namespace detail {

template <class T>
struct is_span_oracle : std::false_type {};

template <class ElementType, size_t Extent>
struct is_span_oracle<span<ElementType, Extent>> : std::true_type {};

template <class T>
constexpr auto is_span_oracle_v = is_span_oracle<T>::value;

template <class T>
struct is_span : public is_span_oracle<std::remove_cv_t<T>> {};

template <class T>
constexpr auto is_span_v = is_span<T>::value;

template <class T>
struct is_std_array_oracle : std::false_type {};

template <class ElementType, std::size_t Extent>
struct is_std_array_oracle<std::array<ElementType, Extent>> : std::true_type {};

template <class T>
struct is_std_array : public is_std_array_oracle<std::remove_cv_t<T>> {};

template <class T>
constexpr auto is_std_array_v = is_std_array<T>::value;

template <size_t From, size_t To>
struct is_allowed_extent_conversion
  : public std::integral_constant<bool, From == To || From == dynamic_extent
                                          || To == dynamic_extent> {};

template <size_t From, size_t To>
constexpr auto is_allowed_extent_conversion_v = is_allowed_extent_conversion<
  From, To>::value;

template <class From, class To>
struct is_allowed_element_type_conversion
  : public std::integral_constant<bool,
                                  std::is_convertible_v<From (*)[], To (*)[]>> {
};

template <class Span, bool IsConst>
class span_iterator {
  using element_type_ = typename Span::element_type;

public:
  using iterator_category = std::random_access_iterator_tag;
  using value_type = std::remove_cv_t<element_type_>;
  using difference_type = typename Span::index_type;

  using reference = std::conditional_t<IsConst, const element_type_,
                                       element_type_>&;
  using pointer = std::add_pointer_t<reference>;

  span_iterator() = default;

  constexpr span_iterator(const Span* span,
                          typename Span::index_type idx) noexcept
    : span_(span), index_(idx) {
  }

  friend span_iterator<Span, true>;

  template <bool B, std::enable_if_t<!B && IsConst>* = nullptr>
  constexpr span_iterator(const span_iterator<Span, B>& other) noexcept
    : span_iterator(other.span_, other.index_) {
  }

  constexpr reference operator*() const {
    return *(span_->data() + index_);
  }

  constexpr pointer operator->() const {
    return span_->data() + index_;
  }

  constexpr span_iterator& operator++() {
    ++index_;
    return *this;
  }

  constexpr span_iterator operator++(int) {
    auto ret = *this;
    ++(*this);
    return ret;
  }

  constexpr span_iterator& operator--() {
    --index_;
    return *this;
  }

  constexpr span_iterator operator--(int) {
    auto ret = *this;
    --(*this);
    return ret;
  }

  constexpr span_iterator operator+(difference_type n) const {
    auto ret = *this;
    return ret += n;
  }

  constexpr span_iterator& operator+=(difference_type n) {
    index_ += n;
    return *this;
  }

  constexpr span_iterator operator-(difference_type n) const {
    auto ret = *this;
    return ret -= n;
  }

  constexpr span_iterator& operator-=(difference_type n) {
    return *this += -n;
  }

  constexpr difference_type operator-(span_iterator rhs) const {
    return index_ - rhs.index_;
  }

  constexpr reference operator[](difference_type n) const {
    return *(*this + n);
  }

  constexpr friend bool operator==(span_iterator lhs,
                                   span_iterator rhs) noexcept {
    return lhs.span_ == rhs.span_ && lhs.index_ == rhs.index_;
  }

  constexpr friend bool operator!=(span_iterator lhs,
                                   span_iterator rhs) noexcept {
    return !(lhs == rhs);
  }

  constexpr friend bool operator<(span_iterator lhs,
                                  span_iterator rhs) noexcept {
    return lhs.index_ < rhs.index_;
  }

  constexpr friend bool operator<=(span_iterator lhs,
                                   span_iterator rhs) noexcept {
    return !(rhs < lhs);
  }

  constexpr friend bool operator>(span_iterator lhs,
                                  span_iterator rhs) noexcept {
    return rhs < lhs;
  }

  constexpr friend bool operator>=(span_iterator lhs,
                                   span_iterator rhs) noexcept {
    return !(rhs > lhs);
  }

protected:
  const Span* span_ = nullptr;
  size_t index_ = 0;
};

template <class Span, bool IsConst>
constexpr span_iterator<Span, IsConst>
operator+(typename span_iterator<Span, IsConst>::difference_type n,
          span_iterator<Span, IsConst> rhs) {
  return rhs + n;
}

template <class Span, bool IsConst>
constexpr span_iterator<Span, IsConst>
operator-(typename span_iterator<Span, IsConst>::difference_type n,
          span_iterator<Span, IsConst> rhs) {
  return rhs - n;
}

template <size_t Ext>
class extent_type {
public:
  using index_type = size_t;

  static_assert(Ext >= 0, "A fixed-size span must be >= 0 in size.");

  constexpr extent_type() noexcept {
  }

  template <index_type Other>
  constexpr extent_type(extent_type<Other>) {
    static_assert(Other == Ext || Other == dynamic_extent,
                  "Mismatch between fixed-size extent and size of initializing "
                  "data.");
  }

  constexpr extent_type(index_type) {
    // nop
  }

  constexpr index_type size() const noexcept {
    return Ext;
  }
};

template <>
class extent_type<dynamic_extent> {
public:
  using index_type = size_t;

  template <index_type Other>
  explicit constexpr extent_type(extent_type<Other> ext) : size_(ext.size()) {
  }

  explicit constexpr extent_type(index_type size) : size_(size) {
    // nop
  }

  constexpr index_type size() const noexcept {
    return size_;
  }

private:
  index_type size_;
};

template <class ElementType, size_t Extent, size_t Offset, size_t Count>
struct calculate_subspan_type {
  using type = span<ElementType,
                    Count != dynamic_extent
                      ? Count
                      : (Extent != dynamic_extent ? Extent - Offset : Extent)>;
};

} // namespace detail

// [span], class template span
template <class ElementType, size_t Extent>
class span {
public:
  // constants and types
  using element_type = ElementType;
  using value_type = std::remove_cv_t<ElementType>;
  using index_type = size_t;
  using pointer = element_type*;
  using reference = element_type&;

  using iterator = detail::span_iterator<span<ElementType, Extent>, false>;
  using const_iterator = detail::span_iterator<span<ElementType, Extent>, true>;
  using reverse_iterator = std::reverse_iterator<iterator>;
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;

  using size_type = index_type;

  static constexpr index_type extent{Extent};

  // [span.cons], span constructors, copy, assignment, and destructor
  template <bool Dependent = false,
            class = std::enable_if_t<(Dependent || Extent == dynamic_extent)>>
  constexpr span() noexcept : storage_(nullptr, detail::extent_type<0>()) {
  }
{'fraction_non_alphanumeric': 0.12230579254602604, 'fraction_numerical': 0.0012348450830713966, 'mean_word_length': 2.8757885577550577, 'pattern_counts': {'":': 0, '<': 166, '<?xml version=': 0, '>': 169, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2186562', 'n_tokens_mistral': 5389, 'n_tokens_neox': 5199, 'n_words': 1404}