<chrono>: Replace an elaborate table with a switch by StephanTLavavej · Pull Request #5905 · microsoft/STL (original) (raw)

<chrono> formatting validated modifier characters by searching an elaborate table containing bitflags of allowed modifiers. It tried to use ranges::find with a PMD projection, but we needed a product code workaround for VSO-1664341 "/clr C++20 System.NullReferenceException when calling ranges algorithms with PMD projections".

I initially tried to replace the ranges::find with a range-for loop as a perma-workaround, which was an improvement, but then I went further. We can replace all of this machinery with a switch.

By changing void _Check_modifier to bool _Valid_modifier, we can further simplify the control flow by immediately returning true or false, and having the caller take care of throwing any exception.

I'm adding _STL_INTERNAL_CHECK(_Modifier == 'E' || _Modifier == 'O'); for a previously implicit assumption.

Finally, I'm adding a comment to cite the relevant Standardese for where this switch's data comes from.