Feature request: etl::constant_map #1148
Closed
relativityspace-jsmith
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
|
Update: Looks like this may already exist 🤦 We will give this a shot, looks like you're way ahead of us! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I would like to put in a request for a new collection in etl. My coworkers and I have seen the need for this several times now, and it would be really incredible if it could be added.
What I would love is a collection that works like an etl::map, except:
constexprif you have compiler support (Hoping for C++17 compatibility🙏)This collection would be super useful for storing constant mappings between one thing and another thing, which is a problem that comes up quite often in embedded development.
For a simple example of why this would be useful, let's look at a basic system for pin mapping:
An etl::map is very useful for this kind of thing, because it gives us an efficient way to search the map based on a given pin number. However, etl::map is not constexpr -- it has to be constructed in RAM, at runtime, based on the initialization data. This leads to two pretty major downsides:
Hopefully you see why the
etl::constant_map(or whatever you'd like to call it) would be useful: it would solve both of these downsides by allowing the compiler to construct the entire map in memory at compile time and then put it into flash memory instead of RAM. I'd really love it if we had a tool like this, as currently we need to use constexpr arrays of pairs, linear searched at runtime, in applications like what I discussed. Alternately, if it's possible to accomplish this using something else in libstdc++ or etl, please let me know, as I'm not aware of a readily available method.P.S. As for how to implement etl::constant_map, I think the easiest way would be to create an array of pairs that gets sorted at compile time. Then
find()could be implemented as a binary search, providing O(logn) runtime.Beta Was this translation helpful? Give feedback.
All reactions