Is constructing std::locale
with an empty string to get the user-preferred native locale a part of the standard? If yes, could you point out a source which explicitly states that?
Example from documentation of std::locale
has this line:
std::wcout << "User-preferred locale setting is " << std::locale("").name().c_str()
Which hints that creating a locale with an empty string will return a user-preferred native locale. After quick googling, this article also mentions:
The empty string tells setlocale to use the locale specified by the user in the environment.
However, when looking at the documentation for std::locale
constructors, there is no mentioning of a special case, when an empty string is provided.
Here's the quote:
3-4) Constructs a copy of the system locale with specified std_name (such as "C", or "POSIX", or "en_US.UTF-8", or "English_US.1251"), if such locale is supported by the operating system. The locale constructed in this manner has a name.
The draft standard says in [locale.cons]:
explicit locale(const char* std_name);
Effects: Constructs a locale using standard C locale names, e.g.,
"POSIX"
. The resulting locale implements semantics defined to be associated with that name.Throws:
runtime_error
if the argument is not valid, or is null.Remarks: The set of valid string argument values is
"C"
,""
, and any implementation-defined values.
This says ""
is a valid constructor argument, and arguments are standard C locale names.
Then in [c.locale] it explicitly refers to the standard C header <locale.h>
.
Quoting from the C standard (C99), 7.11.1.1/3:
A value of
"C"
forlocale
specifies the minimal environment for C translation; a value of""
forlocale
specifies the locale-specific native environment. Other implementation-defined strings may be passed as the second argument tosetlocale
.
I think this means the answer to your question is "yes": A name of ""
refers to the native locale.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With