time_put facet implementation

Paolo Carlini paolo.carlini@oracle.com
Mon Sep 28 15:43:00 GMT 2009


Hi,
> I get a bad cast failure trying to instantiate
>
> std::use_facet<std::time_put<char, std::ostream_iterator<char> > >
>
> This facet does not seem to be implemented in libstdc++ 4.3.2.
>
> It looks like only std::ostreambuf_iterator-based facets are
> implemented in libstdc++, and not std::ostream_iterator-based facets.
Just have a look to the sources, and you will see the facet is
definitely implemented.
> I'm looking at table 52 in 2.1.1.1, "Required Instantiation". I see
> that "time_put<char, OutputIterator>" is listed as a required facet.
> Following it, paragraph 6 specifies that OutputIterator may be
> anything that specifies an output iterator that meets the requirements
> of 24.1. As far as I can figure out, std::ostream_iterator meets those
> requirements, so how come I cannot instantiate this facet? I think I
> should be able to use any iterator, not just std::ostreambuf_iterator,
> and not even just std::ostream_iterator, with all of the output
> iterator facets in this table.
Why do you think you can't instantiate it? Definitely you can, eg, this
works fine:

#include <locale>
#include <iterator>

struct my_facet
: std::time_put<char, std::ostream_iterator<char> >
{
  my_facet() { }
};

my_facet tp;

Note: one thing is *instantiating* the facet, per Table 52, another
thing finding it installed in a given locale: in the latter case Table
51 applies, which concerns only ostreambuf_iterator based facets.

Paolo.



More information about the Libstdc++ mailing list