Abbasi
But how they're faster than std::map?
By the way how are the key kept unique?
Vlad
Vlad
https://godbolt.org/z/GE6E6n7ro
Ludovic 'Archivist'
Your suggestion is to use arrays instead of the std::map?
Yes, std::map is overkill, it is pretty expensive to build, and pretty expensive to look up it. std::map will evict log(n) cache lines when doing your lookup for the value, as well as disrupt the branch predictor, while using an array will literally compile the lookup to one instruction
Ludovic 'Archivist'
Vlad
Vlad
Vlad
Yeah, I'm talking about values though, not references. For references C casts are deadly yeah
Vlad
Not denying that
Vlad
Ludovic 'Archivist'
Vlad
Pavel
Readability is controversial. I feel like c-casts are easier to hide in other code
Ludovic 'Archivist'
Pavel
I think in about all projects I worked on c-casts were banned
Pavel
And reinterpret_cast as well
Vlad
seeing code related makes me nauseous a little bit
int a = ...;
int b = ...;
foobar(static_cast<size_t>(a), static_cast<short>(b));
Vlad
Cant help it
Pavel
Vlad
Vlad
But it aint 40 symbols
Vlad
I get why would you grep reinterpret casts or const casts
Ludovic 'Archivist'
Cayetano
Guys, I guess that you are mixing C and C++. I'm convinced that C++ is enough optimized to use STL and resolve the issues that you are mention... isn't it?
Vlad
Vlad
With like a typename
Vlad
Obviously
Ludovic 'Archivist'
Pavel
Cayetano
Vlad
Obviously
But static casting ints is just pointless
Vlad
Vlad
And then putting std::vector's into std::map
Cayetano
Well, the only way that I find to solve my situation is that, because, if I implement the solution suggested by @Abbasi_dev, that is (following message)
Cayetano
. . .
enum class languages {
es_AR,es_BO,es_CL,es_CO,es_CR,es_DO,es_EC,es_ES,es_GT,
...
};
const std::map<languages, const char *> languagesNames{
{languages::es_AR, "Spanish (Argentina)"},
{languages::es_BO, "Spanish (Bolivia)"},
{languages::es_CL, "Spanish (Chile)"},
....
};
```
Vlad
Cayetano
I get from system a string like "es_ES" or "en_US", and I need to find the match in the enum... How can I do that?
Cayetano
Cayetano
Even if you choose the path to store in a file and load it dinamically... That part I guess that I have clear...
Cayetano
My issue now is, you get from system a string (char*) and you need to find out how to match it to the enum or std::map structures...
Cayetano
Cayetano
But the enum part is what I cannot see clear
Vlad
Abbasi
You can always measure.
Ludovic 'Archivist'
Vlad
Which will be totally fine since not like he's gonna have more than 10 languages
Cayetano
Ludovic 'Archivist'
Ludovic 'Archivist'
why would you use a map
Ludovic 'Archivist'
No defines either
Cayetano
Just a std::map<string, string> to store pairs like {'en_US', 'American English'}?
Ludovic 'Archivist'
just std::array, a reinterpret_cast and enum to int convertions
Ludovic 'Archivist'
Cayetano
Sorry I'm a little bit newbie, how can I use a reinterpret_cast and enum? 🤔 Can you show me briefly, please 🙏?
Ludovic 'Archivist'
Cayetano
Ludovic 'Archivist'
as for the reinterpret cast, look at those language strings and find the character that is so redundant you could remove it
Vlad
Although I would go for char[6] instead
Vlad
Yeah load store would take 2 instructions rather than 1, don't care really
Vlad
It's a language select not a video decoder
Cayetano
hmmm... That's true!
Cayetano
Ok, let me to make some proofs and I'll be back with the final solution... Thank you very much guys!
Orange Juice
Welcome!
Oliver
I have completed MCA course
Oliver
Please give me suggestion to choose the technical field