You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
For a locale which specifies digit grouping, num_get::do_get will enforce
that the number read in contains the grouping character at the correct
locations. It does this even if the number read in didn't have any grouping
characters present.
This is shown best with a code example:
#include
#include
int main()
{
std::locale::global(std::locale("en_US.UTF-8"));
std::istringstream iss("1024");
int a = 0;
iss >> a;
std::cout << a << ", " << iss.fail() << std::endl;
}
Digit grouping is checked. That is, the positions of discarded separators is
examined for consistency with
use_facet<numpunct >(loc).grouping(). If they are not consistent then
ios_base::failbit is assigned to err.
Whilst the standard could be clearer, it seems one can take it to mean that as
there are no discarded characters, there is nothing to examine for consistency.
This is the approach that libstdc++ takes, as well as boost's lexical_cast:
which might have been meant to be != instead of >= in the new line.
At least, according to my compiler, __grouping.size() is unsigned, so >= 0 is invariably true. Should it have been != (or >), or did you mean to remove the now-tautological condition entirely?
Extended Description
For a locale which specifies digit grouping, num_get::do_get will enforce
that the number read in contains the grouping character at the correct
locations. It does this even if the number read in didn't have any grouping
characters present.
This is shown best with a code example:
#include
#include
int main()
{
std::locale::global(std::locale("en_US.UTF-8"));
std::istringstream iss("1024");
int a = 0;
iss >> a;
std::cout << a << ", " << iss.fail() << std::endl;
}
With libc++ this prints:
1024, 1
With libstdc++ this prints:
1024, 0
http://coliru.stacked-crooked.com/a/9283df64c2bd5142
The standard says:
http://eel.is/c++draft/facet.num.get.virtuals#4
Whilst the standard could be clearer, it seems one can take it to mean that as
there are no discarded characters, there is nothing to examine for consistency.
This is the approach that libstdc++ takes, as well as boost's lexical_cast:
https://svn.boost.org/trac/boost/ticket/5585
I think it's reasonable that libc++ changes its implementation to match.
The text was updated successfully, but these errors were encountered: