On 01/13/18 18:20, Peter Dimov via Boost wrote:
Andrey Semashev wrote:
I don't think the standard requires this implementation. > `system_category()` may return a pointer to a global caregory instance, > which is initialized before `main`.
You're not prohibited from calling system_category() before main, so it has to work.
You can see for yourself what happens in practice today: https://godbolt.org/g/1TfPQw
The g++/clang++ generated code looks cleaner than that, but it's because it doesn't include system_category(). Here it is in libc++: https://github.com/llvm-mirror/libcxx/blob/master/src/system_error.cpp#L211
MS's code is even more convoluted because their
works during process shutdown, after static destruction. But the magic static cost is the same in either case.
Here's the gist of what I propose: https://godbolt.org/g/nSiEZZ It's as optimal as it can get, IMHO.