FastLED 3.9.15
Loading...
Searching...
No Matches
initializer_list.h
Go to the documentation of this file.
1
2#pragma once
3
4// IWYU pragma: no_include "__cstddef/size_t.h"
5// IWYU pragma: no_include "__config"
6// IWYU pragma: no_include "version"
7
8#include "platforms/is_platform.h" // IWYU pragma: keep
9
10// Define if initializer_list is available
11// Check for C++11 and if std::initializer_list exists
12#if !defined(FL_IS_AVR)
13// IWYU pragma: begin_keep
14#include <initializer_list> // IWYU pragma: keep
15#include "fl/stl/noexcept.h"
16// IWYU pragma: end_keep
17#endif
18
19#if defined(FL_IS_AVR)
20// Emulated initializer_list for AVR platforms
21// MUST be in std namespace for compiler's brace-initialization magic to work
22
23namespace std {
24 template<typename T>
25 class initializer_list {
26 private:
27 const T* mBegin;
28 unsigned int mSize; // Use unsigned int directly for AVR (16-bit)
29
30 // Private constructor used by compiler
31 constexpr initializer_list(const T* first, unsigned int size)
32 : mBegin(first), mSize(size) {}
33
34 public:
35 using value_type = T;
36 using reference = const T&;
37 using const_reference = const T&;
38 using size_type = unsigned int; // Use unsigned int directly for AVR (16-bit)
39 using iterator = const T*;
40 using const_iterator = const T*;
41
42 // Default constructor
43 constexpr initializer_list() FL_NOEXCEPT : mBegin(nullptr), mSize(0) {}
44
45 // Size and capacity
46 constexpr unsigned int size() const { return mSize; }
47 constexpr bool empty() const { return mSize == 0; }
48
49 // Iterators
50 constexpr const_iterator begin() const { return mBegin; }
51 constexpr const_iterator end() const { return mBegin + mSize; }
52
53 // Allow compiler access to private constructor
54 template<typename U> friend class initializer_list;
55 }; // IWYU pragma: keep
56
57 // Helper functions to match std::initializer_list interface // IWYU pragma: keep
58 template<typename T>
59 constexpr const T* begin(initializer_list<T> il) {
60 return il.begin();
61 }
62
63 template<typename T>
64 constexpr const T* end(initializer_list<T> il) {
65 return il.end();
66 }
67}
68
69// Alias in fl namespace for consistency
70namespace fl {
71 using std::initializer_list; // okay std namespace // ok bare using
72}
73#else
74namespace fl {
75 using std::initializer_list; // okay std namespace // ok bare using
76}
77#endif
constexpr T * begin(T(&array)[N]) FL_NOEXCEPT
constexpr T * end(T(&array)[N]) FL_NOEXCEPT
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT