
Martin wrote:
It's already the case, because config file do not contain the information about the used locale. Further, even if it did, the set of locales on different computers is not the same, and on different OS even the naming may be different, so moving configuration files is hard already. This might mean I need to set classic locale for parsing, to make sure config files are really portable.
I am not familiar with the code layout for program options but with a quick look it seems like you can do it the the same way as in the streams? Add a locale reference member to the value_semantics class and an imbue method to the options_description class which specifies the default.
So every library which uses lexical_cast would have to provide the 'imbue' and store the locale everywhere? I think per-thread global variable is better.
That's not convenient, so probably global "lexical_cast_locale" is better. But for MT environment you need to store that global state in TSS.
The global locale can already be used so there is no need for another global locale.
Nope, there's only one global locale, it's not per-thread. If it's per-thread, you can do std::locale::tss_global(std::locale("koi8-r")); // do some work with program_options std::locale::tss_global(std::locale(""));
const std::locale old = std::locale::global(std::locale::classic()); double x = lexical_cast<double>(str); std::locale::global(old);
But that does not prevent other threads to change the locale again one CPU tick before you you call lexical_cast. - Volodya