make_const_map - #1483
Conversation
|
This is a valid approach, and we can certainly think about updating the CI from using However, this can be implemented for C++14 instead of requiring C++20, opening the feature to many more ETL users currently. E.g. instead of going through template arguments for sort-check, you can make use of the Basic idea: |
|
You can use this demo as a reference: |
|
BTW: Same applies to |
|
Thanks I'll check out that approach |
I played with this a bit and it looks promising. I have a couple observations. The existing Calling the non constexpr I'm not sure why this only works with a derived class Edit: OK now I got it working with the regular const_map class. I'll continue cleaning it up. |
Proposed solution to #1341 .
Adds
make_const_mapandmake_const_map_with_comparerfunctions for assisting with constructing the class. The main thing that they provide is a static_assert that elements provided are sorted. As noted in the issue, the map does not function properly if the elements are not sorted.What I found from research is that with the existing const_map constructor, it is not possible to use the variadic function parameter values at compile time in order to check for sorted. In order to check at compile time the elements must be variadic template parameters.
Because this uses auto template parameters this requires C++20. Also the gcc builds are failing, it seems due to a bug where before gcc12 where std::pair value was not able to be used as template parameter (https://stackoverflow.com/questions/64931324/what-is-the-purpose-of-having-an-empty-pair-base-class). This is working in newer gcc versions, but if this is acceptable than the older gcc version would need to be excluded.
I'll open this up as draft PR to get feedback on the API and implementation.