This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: time_put facet implementation
- From: Paolo Carlini <paolo dot carlini at oracle dot com>
- To: Sam Varshavchik <mrsam at courier-mta dot com>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Mon, 28 Sep 2009 17:43:14 +0200
- Subject: Re: time_put facet implementation
- References: <cone.1253981634.846290.8569.500@commodore.email-scan.com>
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.