Wyatt Hepler | 0412a7d | 2020-01-28 16:27:32 -0800 | [diff] [blame] | 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 | |
Wyatt Hepler | 023f35b | 2020-07-01 09:40:50 -0700 | [diff] [blame] | 18 | #include "pw_polyfill/standard_library/namespace.h" |
| 19 | |
| 20 | _PW_POLYFILL_BEGIN_NAMESPACE_STD |
Wyatt Hepler | 0412a7d | 2020-01-28 16:27:32 -0800 | [diff] [blame] | 21 | |
| 22 | #define __cpp_lib_nonmember_container_access 201411L |
| 23 | |
| 24 | template <typename C> |
Armando Montanez | 187389d | 2020-04-06 17:00:13 -0700 | [diff] [blame] | 25 | auto begin(C& container) -> decltype(container.begin()) { |
| 26 | return container.begin(); |
| 27 | } |
| 28 | |
| 29 | template <typename C> |
| 30 | auto begin(const C& container) -> decltype(container.begin()) { |
| 31 | return container.begin(); |
| 32 | } |
| 33 | |
| 34 | template <typename C> |
Wyatt Hepler | 0412a7d | 2020-01-28 16:27:32 -0800 | [diff] [blame] | 35 | constexpr auto data(C& container) -> decltype(container.data()) { |
| 36 | return container.data(); |
| 37 | } |
| 38 | |
| 39 | template <typename C> |
| 40 | constexpr auto data(const C& container) -> decltype(container.data()) { |
| 41 | return container.data(); |
| 42 | } |
| 43 | |
| 44 | template <typename T, decltype(sizeof(int)) kSize> |
| 45 | constexpr T* data(T (&array)[kSize]) noexcept { |
| 46 | return array; |
| 47 | } |
| 48 | |
| 49 | template <typename C> |
Armando Montanez | 187389d | 2020-04-06 17:00:13 -0700 | [diff] [blame] | 50 | auto end(C& container) -> decltype(container.end()) { |
| 51 | return container.end(); |
| 52 | } |
| 53 | |
| 54 | template <typename C> |
| 55 | auto end(const C& container) -> decltype(container.end()) { |
| 56 | return container.end(); |
| 57 | } |
| 58 | |
| 59 | template <typename C> |
Wyatt Hepler | 0412a7d | 2020-01-28 16:27:32 -0800 | [diff] [blame] | 60 | constexpr auto size(const C& container) -> decltype(container.size()) { |
| 61 | return container.size(); |
| 62 | } |
| 63 | |
| 64 | template <typename T, decltype(sizeof(int)) kSize> |
| 65 | constexpr decltype(sizeof(int)) size(const T (&)[kSize]) noexcept { |
| 66 | return kSize; |
| 67 | } |
| 68 | |
Wyatt Hepler | bc6332c | 2020-02-10 16:34:19 -0800 | [diff] [blame] | 69 | // NOT IMPLEMENTED: iterator_traits does not work |
| 70 | template <typename> |
| 71 | struct iterator_traits {}; |
| 72 | |
Wyatt Hepler | 0412a7d | 2020-01-28 16:27:32 -0800 | [diff] [blame] | 73 | // NOT IMPLEMENTED: Reverse iterators are not implemented. |
| 74 | template <typename> |
| 75 | struct reverse_iterator; |
| 76 | |
Wyatt Hepler | 023f35b | 2020-07-01 09:40:50 -0700 | [diff] [blame] | 77 | _PW_POLYFILL_END_NAMESPACE_STD |