1*09635541SAndroid Build Coastguard Worker /* 2*09635541SAndroid Build Coastguard Worker * Copyright 2024 Google LLC 3*09635541SAndroid Build Coastguard Worker * 4*09635541SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*09635541SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*09635541SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*09635541SAndroid Build Coastguard Worker * 8*09635541SAndroid Build Coastguard Worker * https://www.apache.org/licenses/LICENSE-2.0 9*09635541SAndroid Build Coastguard Worker * 10*09635541SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*09635541SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*09635541SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*09635541SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*09635541SAndroid Build Coastguard Worker * limitations under the License. 15*09635541SAndroid Build Coastguard Worker */ 16*09635541SAndroid Build Coastguard Worker 17*09635541SAndroid Build Coastguard Worker #pragma once 18*09635541SAndroid Build Coastguard Worker 19*09635541SAndroid Build Coastguard Worker #include <cstddef> 20*09635541SAndroid Build Coastguard Worker 21*09635541SAndroid Build Coastguard Worker #if ABSL_INTERNAL_CPLUSPLUS_LANG >= 202002L || __cplusplus >= 202002L 22*09635541SAndroid Build Coastguard Worker #error This trivial span.h should not be used if the platform supports std::span 23*09635541SAndroid Build Coastguard Worker #endif // ABSL_INTERNAL_CPLUSPLUS_LANG >= 202002L || __cplusplus >= 202002L 24*09635541SAndroid Build Coastguard Worker 25*09635541SAndroid Build Coastguard Worker namespace cppbor { 26*09635541SAndroid Build Coastguard Worker 27*09635541SAndroid Build Coastguard Worker template <class T> 28*09635541SAndroid Build Coastguard Worker class span { 29*09635541SAndroid Build Coastguard Worker public: span()30*09635541SAndroid Build Coastguard Worker constexpr span() : mBegin(nullptr), mLen(0) {} span(T * begin,size_t len)31*09635541SAndroid Build Coastguard Worker explicit constexpr span(T* begin, size_t len) : mBegin(begin), mLen(len) {} 32*09635541SAndroid Build Coastguard Worker begin()33*09635541SAndroid Build Coastguard Worker constexpr T* begin() const noexcept { return mBegin; } end()34*09635541SAndroid Build Coastguard Worker constexpr T* end() const noexcept { return mBegin + mLen; } data()35*09635541SAndroid Build Coastguard Worker constexpr T* data() const noexcept { return mBegin; } 36*09635541SAndroid Build Coastguard Worker size()37*09635541SAndroid Build Coastguard Worker constexpr size_t size() const noexcept { return mLen; } 38*09635541SAndroid Build Coastguard Worker 39*09635541SAndroid Build Coastguard Worker private: 40*09635541SAndroid Build Coastguard Worker T* mBegin; 41*09635541SAndroid Build Coastguard Worker size_t mLen; 42*09635541SAndroid Build Coastguard Worker }; 43*09635541SAndroid Build Coastguard Worker 44*09635541SAndroid Build Coastguard Worker } // namespace cppbor 45