// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef PLATFORM_BASE_SPAN_H_ #define PLATFORM_BASE_SPAN_H_ #include <stddef.h> #include <stdint.h> #include <array> #include <cassert> #include <type_traits> #include <vector> #include "platform/base/type_util.h" namespace openscreen { template <typename T> class Span; // In Open Screen code, use these aliases for the most common types of Spans. // These can be converted to use std::span once the library supports C++20. ByteView; ByteBuffer; // Contains a pointer and length to a span of contiguous data. // // The API is a slimmed-down version of a C++20 std::span<T> and is intended to // be forwards-compatible with very slight modifications. We don't intend to // add support for static extents. // // NOTES: // - Although other span implementations allow passing zero to last(), we do // not, as the behavior is undefined. Callers should explicitly create an // empty Span instead. // // - operator== is not implemented to align with std::span. For more // discussion, this blog post has considerations when implementing operators // on types that don't own the data they depend upon: // https://abseil.io/blog/20180531-regular-types // // - Unit tests that want to compare the bytes behind two ByteViews can use // ExpectByteViewsHaveSameBytes(). template <typename T> class Span { … }; } // namespace openscreen #endif // PLATFORM_BASE_SPAN_H_