-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow modification of map values #105
Comments
Well, this would be incompatible with the Would you write the following? constexpr char data[3] = "yo";
data[1] = 'a'; |
Sorry, my example was bad. I did not mean for the map to be #include <frozen/set.h>
#include <frozen/string.h>
#include <frozen/unordered_map.h>
int main() {
frozen::unordered_map<frozen::string, int, 2> fruits = {
{"n_apples", 0},
{"n_pears", 0},
};
fruits.at("n_apples") = 10;
fruits.at("n_pears") = fruits.at("n_apples") * 2;
} I see this does not compile, answering my question if it currently works or not. At a technical level, do you see any reason this could not work? I may be interested in doing it myself. |
With a little modification of the code this example is possible. In particular, it just needs a version of |
…r non-const `frozen::unordered_map`s So far this works. I question if the const-cast is appropriate, however, even if it is recomended. I believe it leaves room for error.
Here's some rough example code peter-moran#1 |
Oh interesting. Indeed the value does not take part in the computation of the keys, so it's legit to think about it. |
If it helps to explain why I am interested in this: I work on a lot of embedded projects where I would love to have a map that does not require dynamic allocation. In most cases I know the keys ahead of time (eg a list of enums or specific strings) but want to change the values associated with those keys over time. Typically for enums I just use an array and use the enums as the array index, but I find it very messy (and it only works with things that implicitly convert to unique integers). In other words, as it stands this library provides a constexpr map, but with a little work it could also provide a fixed size map (or perhaps I would call it an associative array due to its fixed size nature) that allows runtime modification of values. |
Closed by #106 |
…e modification (#106) * Complete implementation of non-const functions for map and unordered_map * Add unit tests * Update README to explain non-constexpr maps
Is it possible, or could it be possible, for this library to let you modify the values in a map? In particular, to maintain the perfect hashing of keys and the fact that there is a constant number of keys, but add the ability to update the values associated with the keys.
Toy example:
The text was updated successfully, but these errors were encountered: