Talk:cpp/locale/num put/put


In the example you have:

  std::ostreambuf_iterator<CharT, Traits> it(os);
         .put(it, os, os.fill(), b.x);

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

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

The first arg. "os" of "put" func will be implicitly converted from "basic_ostream<CharT, Traits>" to "ostreambuf_iterator<CharT, Traits>".

Thank you.

vlakov -- 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 do_put), or maybe move it into the [operator<< page as a "possible implementation" (which is a different section from "example") --Cubbi (talk) 17:29, 22 March 2014 (PDT)
Every example that is on is very helpful. Eliminating examples will not help too much to mortals like me. --vlakov 23:29, 22 March 2014 (PDT)