C++11: is std::locale::empty() even a thing?

给你一囗甜甜゛ 提交于 2021-02-08 16:54:45

问题


Trying to compile some code from StackOverflow, basically, these lines:

std::wifstream wif(filename);
wif.imbue(std::locale(std::locale::empty(), new std::codecvt_utf8<wchar_t>));

GCC version: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0

I get a compile error:

'empty' is not a member of 'std::locale'

And I agree with the compiler, checked with documentation like cppreference - there is no info about such thing. Header files as well do not show anything.

I wonder, if this is just me or the sample code from another topic...

Can it be a MSVC feature? (the sample code I used is from the question related to Windows)


回答1:


This is a platform-specific extension to the locale class, and it used to be described in this MSVC documentation*:

In this implementation, you can also call the static member function:

static locale empty( );

to construct a locale object that has no facets. It is also a transparent locale; if the template functions has_facet and use_facet cannot find the requested facet in a transparent locale, they consult first the global locale and then, if that is transparent, the classic locale.

* the MSVC documentation link is outdated now, for best replacement see this documentation page instead



来源:https://stackoverflow.com/questions/41753308/c11-is-stdlocaleempty-even-a-thing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!