Earlier quoted context omitted.
Because with a constexpr declaration everything will be constexpr, i.e. you couldn't modify the values at run-time. The idea here is that finding the storage of the value is done at compile-time, but the values themselves are run-time values.
Thanks, I wasn't very clear but now I see the problem. The C++ invocation syntax (basically the difference between expressions and statements inherited from Algol) makes it impossible to call if you want to update it at runtime. You could declare `static static_map ::Value& get()` constexpr. (Actually you wouldn't need to; I think you could simply declare `semi::map ::get()` to be constexpr) and I believe it would al…
C++: Associative map containers with compile-time lookup
41–45 of 45 posts
Re: C++: Associative map containers with compile-time lookup
#42Earlier quoted context omitted.
Thanks, I wasn't very clear but now I see the problem. The C++ invocation syntax (basically the difference between expressions and statements inherited from Algol) makes it impossible to call if you want to update it at runtime. You could declare `static static_map ::Value& get()` constexpr. (Actually you wouldn't need to; I think you could simply declare `semi::map ::get()` to be constexpr) and I believe it would al…
Hmmm, I'm not sure I understand. You can't really mark `static static_map ::Value& get()` constexpr because it returns a value which is only known at run-time - again the value is a run-time value, only the lookup (where in memory) is at compile-time. This has nothing to do with inlining.
I didn't look closely enough and assumed you'd made your own hash lookup so that parts of it could be run at compile time (in fact you could intern compile-time keys statically in the front of an object (in the initialized data section of the object file) adding a single additional probe at runtime) and let the linker patch up the locations in the usual fashion.
This is all a move in the right direction!
Re: C++: Associative map containers with compile-time lookup
#43CppCon has super interesting content. That comes from a person who has written maybe two dozen lines of C++ code, mostly just hello world. E.g. this talk by Matt Godbolt or anything by Chadler Carruth. https://www.youtube.com/watch?v=bSkpMdDe4g4
Examples:
- Ben Deane - Using Types Effectively [0]
- Jason Turner - Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17 [1]
- Ben Deane & Jason Turner - constexpr ALL the Things! [2]
[0] https://www.youtube.com/watch?v=ojZbFIQSdl8
Re: C++: Associative map containers with compile-time lookup
#44CppCon has super interesting content. That comes from a person who has written maybe two dozen lines of C++ code, mostly just hello world. E.g. this talk by Matt Godbolt or anything by Chadler Carruth. https://www.youtube.com/watch?v=bSkpMdDe4g4
Also highly recommended: Anything by Jason Turner and Ben Deane. Examples: - Ben Deane - Using Types Effectively [0] - Jason Turner - Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17 [1] - Ben Deane & Jason Turner - constexpr ALL the Things! [2] [0] https://www.youtube.com/watch?v=ojZbFIQSdl8 [1] https://www.youtube.com/watch?v=zBkNBP00wJE [2] https://www.youtube.com/watch?v=PJwd4JLYJJY
Re: C++: Associative map containers with compile-time lookup
#45I can see how `semi::map` could be useful, but `semi::static_map` just seems to be an alternate syntax for global variables.
Yes, in a way you are right: the compiler really does boil it down to global variables. However, `semi::static_map` gives you some additional features, which may be useful for a lot of situations 1) `semi::static_map` gives you the optional run-time look-up with the same API (`semi::static_map::get`). Looking up a global variable with a runtime key isn't straight-forward. This makes it particularly nice to use an API…