FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
initializer_list.h
1// Copyright 2016-2023 Jean-Francois Poilpret
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://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,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
16#ifndef INITIALIZER_LIST_HH
17#define INITIALIZER_LIST_HH
18
19#include <stddef.h>
20
28namespace std
29{
56 template<class T> class initializer_list
57 {
58 private:
59 const T* array_ = nullptr;
60 size_t len_ = 0;
61
62 // The compiler can (and will) call a private constructor.
63 // This constructor will get called when the compiler encounters a braced
64 // list expression with elements of type T, like in f({t1, t2, t3}) and
65 // an initializer_list<T> is expected by f function.
66 constexpr initializer_list(const T* array, size_t len) : array_{array}, len_{len} {}
67
68 public:
70 constexpr initializer_list() = default;
71
73 constexpr size_t size() const
74 {
75 return len_;
76 }
77
79 constexpr const T* begin() const
80 {
81 return array_;
82 }
83
85 constexpr const T* end() const
86 {
87 return begin() + size();
88 }
89 };
90}
91
92#endif /* INITIALIZER_LIST_HH */
C++ standard support for "initializer_list".
constexpr const T * begin() const
The first element of this initializer_list.
constexpr size_t size() const
The size of this initializer_list.
constexpr const T * end() const
One past the last element of this initializer_list.
constexpr initializer_list()=default
Create an empty initializer list.
Similar to standard C++ std namespace, this namespace is used by FastArduino library to implement var...