Boost logo

Boost :

Subject: Re: [boost] [Filesystem.v3] Request to rename imbue to something else like global_locale
From: Artyom (artyomtnk_at_[hidden])
Date: 2011-03-11 10:53:58


> From: "Stewart, Robert" <Robert.Stewart_at_[hidden]>

>
> Artyom wrote:
> >
> > The static member function
> >
> > boost::filesystem::path::imbue(std::locale const &)
> >
> > Is very misleading.
> >
> > boost::filesystem::path p;
> > p.imbue(some_locale);
> > p="some_file.txt";
> >
> > Which looks like you change p's locale and not global locale.
>
> I certainly thought so from the various examples like that I've seen on this
>list.
>
> (I never read the documentation nor noted that imbue() was static, but the
>code above
> in no way appears to affect all instances.)
>

It is just C++, you can call static member function like it is ordinary one.
The problem is that imbue in STL and in Boost (regex for example) refers
to instance and not to something global.

 
> > I'd recommend, provide static member function
> >
> > boost::filesystem::path::global_locale
>
> "default_locale" would be better since it only affects
> filesystem::path objects, not everything in the system.
> That name may not be good enough, though:
>
> p.default_locale(some_locale);
>
> That still seems to affect only the instance, though somewhat less than does
>"imbue."
>

See comments above.

> > With same semantics as imbue and deprecate imbue.
>
> Why not keep imbue() but make it affect individual instances,
> then add a new function that affects all instances not otherwise affected by a
>call to imbue()?
> That suggests a locale pointer in each instance that, if null, means to use
>the default locale.
>

I had been thinking about it, the point is that boost::filesystem::path does not
need
locale instantly it needs it only on the point of conversion between character
path and internal
path type which is done immediately. So if you need some path specific locale it
allows
you (if I'm not mistaken about exact syntax) to call

   p =
fs::path("some_string",std::use_facet<std::codecvt<wchar_t,char,mbstate_t>
>(some_locale));

   Even it is not so nice.

So I can suggest that it should have a constructors like

   path(char const *,std::locale const &)
   path(wchar_t const *,std::locale const &)

In addition to something like

   path(char const *, std::codecvt<wchar_t,char,mbstate_t> const &cvt=codecvt())
   path(wchar_t const *, std::codecvt<wchar_t,char,mbstate_t> const
&cvt=codecvt())

So the above would look like

   p = fs::path("some_string",some_locale);

Much nicer.

Also I would suggest that boost::filesystem could use std::locale's global
locale if it is
not std::locale::classic() (which can be checked easily) or its own locale, but
this is
different story.

This is because the default global locale is usually not good enough as it is
std::locale::classic()
by default and its codecvt facet is useless.

Artyom

      


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk