-
-
Notifications
You must be signed in to change notification settings - Fork 173
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
Better-enum in maps #98
Comments
It's been a long time, but it looks like there is an intermediate call to a default constructor somewhere during the insert. I'm not immediately sure what the best solution to this is, but you should be able to work around it in at least one way by declaring the constructor |
Use BETTER_ENUM(encodings_e, int,
RED,
GREEN,
BLUE
)
std::unordered_map<std::string, encodings_e> map;
map.emplace(std::make_pair("rr", encodings_e::RED);
encodings_e foo = map["rr"];
std::cout << foo._to_string() << std::endl; Edit: @aantron come to think of it, I believe |
@aantron since I'm dealing with Better Enums now anyway I've tested this, also using gcc 9.3. TL;DR: The result is that Also, consider the following notes from
All in all, insert via Sample code: #include <iostream>
#include <map>
#include <better-enums/enum.h>
BETTER_ENUM(mbool, char, mfalse = 0, mtrue = 1)
int main() {
std::map<std::string, mbool> map;
map.emplace(std::make_pair("true", mbool::mfalse));
//const auto t = map["true"]; // compiler error
const auto t = map.at("true");
//std::cout << map["true"] << std::endl; // compiler error
std::cout << map.at("true") << std::endl;
std::cout << t << std::endl;
return 0;
} |
I haven't tried |
@biziosan I don't know if you read my last message, but regardless of |
@jaskij Hi, yes, thank you! It matches with I have working. I used @aantron suggestion about public default constructors and enabled them (https://aantron.github.io/better-enums/OptInFeatures.html#DefaultConstructors). That worked right away! I think I am satisfied with the answers. I can close this issue if you want. |
Hi there,
Thank you for your library! I have the following issue, and I am wondering if there is something I am missing.
When I compile (GCC 9.3 - Linux) this simple piece of code:
I get the following error:
Line 22 where the error happens is on the insertion of the enum in the map.
The text was updated successfully, but these errors were encountered: