blob: 09b0c7020ce200e90fc198e441ff24adc56c78b5 [file] [log] [blame]
Wyatt Hepler0412a7d2020-01-28 16:27:32 -08001// 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
Wyatt Hepler023f35b2020-07-01 09:40:50 -070018#include "pw_polyfill/standard_library/namespace.h"
19
20_PW_POLYFILL_BEGIN_NAMESPACE_STD
Wyatt Hepler0412a7d2020-01-28 16:27:32 -080021
22#define __cpp_lib_nonmember_container_access 201411L
23
24template <typename C>
Armando Montanez187389d2020-04-06 17:00:13 -070025auto 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>
Wyatt Hepler0412a7d2020-01-28 16:27:32 -080035constexpr 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>
Armando Montanez187389d2020-04-06 17:00:13 -070050auto 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>
Wyatt Hepler0412a7d2020-01-28 16:27:32 -080060constexpr 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
Wyatt Heplerbc6332c2020-02-10 16:34:19 -080069// NOT IMPLEMENTED: iterator_traits does not work
70template <typename>
71struct iterator_traits {};
72
Wyatt Hepler0412a7d2020-01-28 16:27:32 -080073// NOT IMPLEMENTED: Reverse iterators are not implemented.
74template <typename>
75struct reverse_iterator;
76
Wyatt Hepler023f35b2020-07-01 09:40:50 -070077_PW_POLYFILL_END_NAMESPACE_STD