// // Copyright 2019 The Abseil Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #ifndef ABSL_TYPES_INTERNAL_SPAN_H_ #define ABSL_TYPES_INTERNAL_SPAN_H_ #include #include #include #include #include "absl/algorithm/algorithm.h" #include "absl/base/internal/throw_delegate.h" #include "absl/meta/type_traits.h" namespace absl { namespace span_internal { // A constexpr min function constexpr size_t Min(size_t a, size_t b) noexcept { return a < b ? a : b; } // Wrappers for access to container data pointers. template constexpr auto GetDataImpl(C& c, char) noexcept // NOLINT(runtime/references) -> decltype(c.data()) { return c.data(); } // Before C++17, std::string::data returns a const char* in all cases. inline char* GetDataImpl(std::string& s, // NOLINT(runtime/references) int) noexcept { return &s[0]; } template constexpr auto GetData(C& c) noexcept // NOLINT(runtime/references) -> decltype(GetDataImpl(c, 0)) { return GetDataImpl(c, 0); } // Detection idioms for size() and data(). template using HasSize = std::is_integral().size())>>; // We want to enable conversion from vector to Span but // disable conversion from vector to Span. Here we use // the fact that U** is convertible to Q* const* if and only if Q is the same // type or a more cv-qualified version of U. We also decay the result type of // data() to avoid problems with classes which have a member function data() // which returns a reference. template using HasData = std::is_convertible()))>*, T* const*>; // Extracts value type from a Container template struct ElementType { using type = typename absl::remove_reference_t::value_type; }; template struct ElementType { using type = T; }; template using ElementT = typename ElementType::type; template using EnableIfMutable = typename std::enable_if::value, int>::type; template