|
Boost Users : |
From: Richard (legalize_at_[hidden])
Date: 2007-12-27 12:31:25
In article <4773AFA2.2080201_at_[hidden]>,
Jeff Garland <jeff_at_[hidden]> writes:
> Richard wrote:
> > In article <4772F58B.8080908_at_[hidden]>,
> > Jeff Garland <jeff_at_[hidden]> writes:
> >
> >> The new is NOT superfluous. The constructor of std::locale takes a pointer
to
> >> a reference counted facet -- effectively taking ownership of the memory.
> >
> > Does it call delete on it?
>
> Yes -- there's an internal reference count in the facet so that facets can be
> shared by multiple streams.
And No -- if you pass a positive value for the reference count to the
facet c'tor then it doesn't call delete on the pointer. So you could
do that code without calling new as follows:
int main()
{
ptime t1(date(2007, Dec, 26), hours(1) + seconds(5) + milliseconds(9));
time_facet timefacet("%a, %d %b %Y %H:%M:%S %z",
time_facet::period_formatter_type(),
time_facet::specialvalues_formatter_type(),
time_facet::date_gen_formatter_type(),
1);
std::cout.imbue(std::locale(std::locale::classic(), &timefacet));
std::cout << t1 << std::endl; //Wed, 26 Dec 2007 01:00:05
}
Which is admittedly more clunky to work with, but then again all the
locale stuff feels that way to me.
I'm not sure if you need to reverse the effects of the imbue before
you leave main() either, that might be something else that locales
require for this to work properly.
-- "The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download <http://www.xmission.com/~legalize/book/download/index.html> Legalize Adulthood! <http://blogs.xmission.com/legalize/>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net