chromium/third_party/inspector_protocol/crdtp/span.h

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CRDTP_SPAN_H_
#define CRDTP_SPAN_H_

#include <cstdint>
#include <cstring>
#include <string>
#include <type_traits>

#include "export.h"

namespace crdtp {
// =============================================================================
// span - sequence of bytes
// =============================================================================

// This template is similar to std::span, which will be included in C++20.
template <typename T>
class span {};

template <size_t N>
constexpr span<char> MakeSpan(const char (&str)[N]) {}

template <size_t N>
constexpr span<uint8_t> SpanFrom(const char (&str)[N]) {}

constexpr inline span<uint8_t> SpanFrom(const char* str) {}

inline span<uint8_t> SpanFrom(const std::string& v) {}

// This SpanFrom routine works for std::vector<uint8_t> and
// std::vector<uint16_t>, but also for base::span<const uint8_t> in Chromium.
template <typename C,
          typename = std::enable_if_t<
              std::is_unsigned<typename C::value_type>{}

// Less than / equality comparison functions for sorting / searching for byte
// spans.
CRDTP_EXPORT bool SpanLessThan(span<uint8_t> x, span<uint8_t> y) noexcept;
CRDTP_EXPORT bool SpanEquals(span<uint8_t> x, span<uint8_t> y) noexcept;

// Less than / equality comparison functions for sorting / searching for byte
// spans.
CRDTP_EXPORT bool SpanLessThan(span<char> x, span<char> y) noexcept;
CRDTP_EXPORT bool SpanEquals(span<char> x, span<char> y) noexcept;

struct SpanLt {};
}  // namespace crdtp

#endif  // CRDTP_SPAN_H_