1// Copyright 2020 The Pigweed Authors 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); you may not 4// use this file except in compliance with the License. You may obtain a copy of 5// the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12// License for the specific language governing permissions and limitations under 13// the License. 14#pragma once 15 16#include <cstddef> 17 18#include "pw_polyfill/standard_library/namespace.h" 19 20_PW_POLYFILL_BEGIN_NAMESPACE_STD 21 22#define __cpp_lib_nonmember_container_access 201411L 23 24template <typename C> 25auto begin(C& container) -> decltype(container.begin()) { 26 return container.begin(); 27} 28 29template <typename C> 30auto begin(const C& container) -> decltype(container.begin()) { 31 return container.begin(); 32} 33 34template <typename C> 35constexpr auto data(C& container) -> decltype(container.data()) { 36 return container.data(); 37} 38 39template <typename C> 40constexpr auto data(const C& container) -> decltype(container.data()) { 41 return container.data(); 42} 43 44template <typename T, decltype(sizeof(int)) kSize> 45constexpr T* data(T (&array)[kSize]) noexcept { 46 return array; 47} 48 49template <typename C> 50auto end(C& container) -> decltype(container.end()) { 51 return container.end(); 52} 53 54template <typename C> 55auto end(const C& container) -> decltype(container.end()) { 56 return container.end(); 57} 58 59template <typename C> 60constexpr auto size(const C& container) -> decltype(container.size()) { 61 return container.size(); 62} 63 64template <typename T, decltype(sizeof(int)) kSize> 65constexpr decltype(sizeof(int)) size(const T (&)[kSize]) noexcept { 66 return kSize; 67} 68 69// NOT IMPLEMENTED: iterator_traits does not work 70template <typename> 71struct iterator_traits {}; 72 73// NOT IMPLEMENTED: Reverse iterators are not implemented. 74template <typename> 75struct reverse_iterator; 76 77_PW_POLYFILL_END_NAMESPACE_STD 78