![](/img/trans.png)
[英]Why does std::locale(“”).name() give different results on clang and gcc?
[英]combine does not change the locale name
对于以下代码:
#include <iostream>
#include <locale>
int main()
{
std::locale loc = std::locale()
.combine<std::numpunct<char>>(std::locale("en_US.UTF-8"));
std::cout << loc.name() << '\n';
std::cout << (std::locale() == loc);
}
当使用 gcc 和 clang 编译时,output 为C
和1
( https://godbolt.org/z/q8fT4oqj3 )。 但是 cppreference 说combine()
将返回一个新的、无名的语言环境。
我完全糊涂了:
如果combine()
返回一个无名的语言环境,那么为什么语言环境的名称仍然是“C”?
如果operator==
返回1
,那么如何区分它们?
看起来应该按照标准返回"*"
:
template <class Facet> locale combine(const locale& other) const;
- 效果:构造一个包含来自
*this
的所有方面的语言环境,除了由Facet
标识的 other 的一个方面。- 返回:新创建的语言环境。
- 抛出:如果
runtime_error
has_facet<Facet>(other)
为假,则运行时错误。- 备注:生成的语言环境没有名称。
basic_string<char> name() const;
- 返回:
*this
的名字,如果有的话; 否则,字符串"*"
。 如果*this
有名称,则locale(name().c_str())
等同于*this
。 结果字符串内容的详细信息由实现定义。
所以它看起来像一个错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.