Introduce ARDUINO_USE_STL
flag
#10774
mathieucarbou
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello guys,
This idea comes from several discussions I had during the past months. People are more and more using Arduino Core with STL library and recent boards such as ESP32 ones. But Arduino Core still has to support more limited boards such as AVR, where STL is not available.
Example of such discussions: https://discord.com/channels/1263397951829708871/1318551945790881792.
But there are plenty others around.
I thought several times about this idea, but more and more I think it could be a helper to introduce it...
The idea would be to have a
ARDUINO_USE_STL
flag that users could set.If set:
String
would be kept but swapped tostd::string
(i.e.using String = std::string
)any custom-made structures replacing STL ones would map to STL ones
Projects using
std::string
with Arduino Core won't have to deal with the inefficiency of converting String objects to std::string onesLibraries could use such flags to optimise their code size in flash: I especially think about WebServer use case where a lof of custom linked lists structures are used (feat(webserver): Middleware with default middleware for cors, authc, curl-like logging #10750), when std::list could be used instead. STL users already have these in flash, so using them instead makes sense.
@me-no-dev wrote about the idea of introducing custom lists, vectors, etc (feat(webserver): Middleware with default middleware for cors, authc, curl-like logging #10750 (comment)). If this is done, with such flags, this could be done in a STL-compatible way, such that activating
ARDUINO_USE_STL
would just swap these custom implementations with STL onesI've already implemented similar idea in ESP-DASH (oss and pro) here: ayushsharma82/ESP-DASH#246, which is a complex use case with templating support, move semantic, polymorphism and String to type T conversion. Users can choose which
String
implementation they want.In the case of Arduino Core, this would mean duplicating the CI to build with the flag on and off.
I did a search on the code base: there are around 1220 occurrences of
String
(only counting the runtime code, excluding doc and examples). So that's not a lot. And most of them are used either for concatenation or method return, and both use cases are compatible between STL and String. From what I learned doing that past months, the API between STL string and String are really similar with a few caveats to pay attention to when concatenating or constructing a string.The goal of these changes would be that Arduino Core avoids dragging some stuff only implemented and required to support more limited board, and embrace better the use of STL in projects where STL is used.
Let ne know what you think.
Happy Christmas to you all! 🎄
Beta Was this translation helpful? Give feedback.
All reactions