Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_minimal_cpp_stdlib / public / internal / iterator.h
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
24 template <typename C>
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>
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>
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>
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
69 // NOT IMPLEMENTED: iterator_traits does not work
70 template <typename>
71 struct iterator_traits {};
72
73 // NOT IMPLEMENTED: Reverse iterators are not implemented.
74 template <typename>
75 struct reverse_iterator;
76
77 _PW_POLYFILL_END_NAMESPACE_STD