Talk:cpp/locale/num put/put

In the example you have:

std::ostreambuf_iterator it(os); std::use_facet>(os.getloc) .put(it, os, os.fill, b.x);

But in the example "std::num_put" is wrongly using "default" ostreambuf_iterator with "default" Traits which is a problem if the "basic_ostream" uses some "non-default" Traits. Shouldn't it be rather ?:

// std::ostreambuf_iterator it(os); std::use_facet>>(os.getloc) .put(os, os, os.fill, b.x);

The first arg. "os" of "put" func will be implicitly converted from "basic_ostream" to "ostreambuf_iterator".

Thank you.

vlakov --193.58.194.195 20:32, 21 March 2014 (PDT)


 * That example is already part-pseudocode (the part that sets badbit and rethrows the original exception if badbit is set is just a comment) - and you point out another reason why it's not suitable for use in a library. Personally, I am not sure it's helpful at all - I'd rather nix it and only keep the one that extends the facet (since that demonstrates why there is a ), or maybe move it into the [operator<< page as a "possible implementation" (which is a different section from "example") --[[User:Cubbi|Cubbi]] (talk) 17:29, 22 March 2014 (PDT)


 * Every example that is on en.cppreference.com is very helpful. Eliminating examples will not help too much to mortals like me. --vlakov 88.212.37.48 23:29, 22 March 2014 (PDT)

The note says `The leading zero generated by the conversion specification #o` is not counted as a padding character. But if this zero should be separated by thousands separator in Stage 2? Or undefined behaviour? with CLang prefix zero is separated while gcc doesn't.

struct my_format : std::numpunct { char do_thousands_sep const override { return ','; } std::string do_grouping const override { return "\3"; } } en_us; std::cout.imbue(std::locale(std::locale, &en_us)); std::cout << std::oct << std::showbase << 0123456 << std::endl;

what should the result be, "0123,456" or "0,123,456" ?


 * nice repro. This would be a good question for std-discussion --Cubbi (talk) 06:29, 2 July 2018 (PDT)