
Hi Robert, I'd like to use add_facet from serialization in the iostreams library, but I don't understand why the generated locale is dynamically allocated. It would seem be more reusable to declare it as follows: template<typename Facet> inline std::locale add_facet(const std::locale& loc, Facet* facet); If you need a dynamically allocated locale, you could write new std::locale(add_facet(loc, facet)) Jonathan

add_facet got added to address a short-coming of the older dinkumware library. It would not really be needed except for this. As to why I did it they way I did - I don't remember. I would guess that I didn't want any more copying than necessary and this implementation worked fine for me. If you want to make version similar to that which you propose and put it an agreed upon public place, I can eventually included your more generally usual formulation Robert Ramey Jonathan Turkanis wrote:
Hi Robert,
I'd like to use add_facet from serialization in the iostreams library, but I don't understand why the generated locale is dynamically allocated. It would seem be more reusable to declare it as follows:
template<typename Facet> inline std::locale add_facet(const std::locale& loc, Facet* facet);
If you need a dynamically allocated locale, you could write
new std::locale(add_facet(loc, facet))
Jonathan
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Robert Ramey wrote:
add_facet got added to address a short-coming of the older dinkumware library. It would not really be needed except for this.
As to why I did it they way I did - I don't remember. I would guess that I didn't want any more copying than necessary and this implementation worked fine for me.
Sounds reasonable. My guess is that the extra copy will typically be optimized away, but I haven't verified this.
If you want to make version similar to that which you propose and put it an agreed upon public place, I can eventually included your more generally usual formulation
Okay.
Robert Ramey
Jonathan

Jonathan Turkanis wrote:
Robert Ramey wrote:
add_facet got added to address a short-coming of the older dinkumware library. It would not really be needed except for this.
As to why I did it they way I did - I don't remember. I would guess that I didn't want any more copying than necessary and this implementation worked fine for me.
Sounds reasonable. My guess is that the extra copy will typically be optimized away, but I haven't verified this.
Hmmm - I would have thought the way its done now ther would be no copying necessary at all. Also, I checked the documentation (msvc 7.1) and it didnt' show a copy constructor, I suppose I presumed erroneously that there was one. For some reason I seem to think that copying a locale wasn't a good idea as I was storing a copy in the archive - and I sort of remember some issues when archives where deleted re garding the sequence of destruction. Also I found a number of subtle difference in stream implementations that really drove me crazy (of course that's why add_facet exists). On the other hand maybe I just did it that way without thinking. oh well, I guess we'll just have to test it.
If you want to make version similar to that which you propose and put it an agreed upon public place, I can eventually included your more generally usual formulation
Okay.
Robert Ramey
Jonathan
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Robert Ramey wrote:
Jonathan Turkanis wrote:
Robert Ramey wrote:
add_facet got added to address a short-coming of the older dinkumware library. It would not really be needed except for this.
As to why I did it they way I did - I don't remember. I would guess that I didn't want any more copying than necessary and this implementation worked fine for me.
Sounds reasonable. My guess is that the extra copy will typically be optimized away, but I haven't verified this.
Hmmm - I would have thought the way its done now ther would be no copying necessary at all. Also, I checked the documentation (msvc 7.1) and it didnt' show a copy constructor, I suppose I presumed erroneously that there was one.
Yes, you're right. Dinkumware doesn't document the copy constructor. But it's definitely there (and it's nothrow, too)
For some reason I seem to think that copying a locale wasn't a good idea as I was storing a copy in the archive -
locales are meant to be pretty trivial to copy. The facets should be stored as pointers and are not copied directly. Copying mainly involves updating reference counts. As a result, you should be able to store an archive's locale by value, rather than using a scoped pointer, as it appears you do. (But I am not suggesting you change anything.)
and I sort of remember some issues when archives where deleted re garding the sequence of destruction. Also I found a number of subtle difference in stream implementations that really drove me crazy (of course that's why add_facet exists). On the other hand maybe I just did it that way without thinking. oh well, I guess we'll just have to test it.
I'm sure you'll remember the problems as soon as they happen again ;-) Jonathan
participants (2)
-
Jonathan Turkanis
-
Robert Ramey