From fb49b6d5bb63b2395dbae0543e1a7e98ed03c04a Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Fri, 5 Dec 2025 16:27:00 -0300 Subject: [PATCH 1/2] feat(string): Add initializer list constructor --- cores/esp32/WString.cpp | 7 +++++++ cores/esp32/WString.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/cores/esp32/WString.cpp b/cores/esp32/WString.cpp index 7210dfbfbc4..ead5721b9e3 100644 --- a/cores/esp32/WString.cpp +++ b/cores/esp32/WString.cpp @@ -59,6 +59,13 @@ String::String(StringSumHelper &&rval) { init(); move(rval); } + +String::String(std::initializer_list list) { + init(); + if (list.size() > 0) { + copy(list.begin(), list.size()); + } +} #endif String::String(char c) { diff --git a/cores/esp32/WString.h b/cores/esp32/WString.h index a8327f40de0..44f9c782e08 100644 --- a/cores/esp32/WString.h +++ b/cores/esp32/WString.h @@ -29,6 +29,7 @@ #include #include #include +#include // A pure abstract class forward used as a means to proide a unique pointer type // but really is never defined. @@ -58,6 +59,7 @@ class String { String(const char *cstr, unsigned int length); #ifdef __GXX_EXPERIMENTAL_CXX0X__ String(const uint8_t *cstr, unsigned int length) : String(reinterpret_cast(cstr), length) {} + String(std::initializer_list list); #endif String(const String &str); String(const __FlashStringHelper *str) : String(reinterpret_cast(str)) {} From f63439977db3cb7594c39b404dd229e7946cce0f Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Sat, 6 Dec 2025 10:04:54 -0300 Subject: [PATCH 2/2] fix(mac): Add initializer list constructor --- cores/esp32/MacAddress.cpp | 18 ++++++++++++++++++ cores/esp32/MacAddress.h | 9 +++++++++ cores/esp32/WString.h | 2 ++ 3 files changed, 29 insertions(+) diff --git a/cores/esp32/MacAddress.cpp b/cores/esp32/MacAddress.cpp index 8b4fab1781a..279b2512633 100644 --- a/cores/esp32/MacAddress.cpp +++ b/cores/esp32/MacAddress.cpp @@ -32,6 +32,24 @@ MacAddress::MacAddress(const String &macstr) { fromString(macstr.c_str()); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +MacAddress::MacAddress(std::initializer_list list) { + size_t size = list.size(); + memset(_mac.bytes, 0, sizeof(_mac.bytes)); + if (size == 6) { + _type = MAC6; + } else if (size == 8) { + _type = MAC8; + } else { + // Default to MAC6 and keep the rest of the bytes as 0 + _type = MAC6; + return; + } + + memcpy(_mac.bytes, list.begin(), size); +} +#endif + MacAddress::MacAddress(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6) { _type = MAC6; memset(_mac.bytes, 0, sizeof(_mac.bytes)); diff --git a/cores/esp32/MacAddress.h b/cores/esp32/MacAddress.h index 5b42649c774..1fb7029dbfd 100644 --- a/cores/esp32/MacAddress.h +++ b/cores/esp32/MacAddress.h @@ -23,6 +23,9 @@ #include #include #include +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#include +#endif enum MACType { MAC6, @@ -56,6 +59,12 @@ class MacAddress : public Printable { MacAddress(const char *macstr); MacAddress(const String &macstr); +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // Initializer list constructor for {0xAA, 0xBB, ...} syntax + // This has higher priority than String conversion, preventing ambiguity + MacAddress(std::initializer_list list); +#endif + virtual ~MacAddress() {} bool fromString(const char *buf); diff --git a/cores/esp32/WString.h b/cores/esp32/WString.h index 44f9c782e08..d9cc7859230 100644 --- a/cores/esp32/WString.h +++ b/cores/esp32/WString.h @@ -29,7 +29,9 @@ #include #include #include +#ifdef __GXX_EXPERIMENTAL_CXX0X__ #include +#endif // A pure abstract class forward used as a means to proide a unique pointer type // but really is never defined.