Re: [boost] Re: compressed_pair requirements?

----- Mensaje original ----- De: Peter Dimov <pdimov@mmltd.net> Fecha: Viernes, Mayo 27, 2005 11:10 pm Asunto: Re: [boost] Re: compressed_pair requirements?
JOAQUIN LOPEZ MU?Z wrote:
IMHO, std::pair default ctor should be defined as
pair():first(),second(){}
This doesn't change things. pair() {} is what you probably want.
Why? (This is not a rethoric question, my understanding of value-initialization matters is so poor.)
What can I say, I'm glad that your and Howard's view didn't prevail when std::pair was being defined. If I had it MY way,
typedef set<int> int_set; pair<int_set::iterator,int_set::iterator> p;
would have compiled on no compiler because int_set::iterator wouldn't even have had a default constructor.
I think there's some value in having iterators being DefaultConstructible. Otherwise you're forced to have some container around everytime you construct an iterator. Defaut construction for iterators is roughly the equivalent of initializing to 0 in the case of pointers. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

JOAQUIN LOPEZ MU?Z wrote:
----- Mensaje original ----- De: Peter Dimov <pdimov@mmltd.net> Fecha: Viernes, Mayo 27, 2005 11:10 pm Asunto: Re: [boost] Re: compressed_pair requirements?
JOAQUIN LOPEZ MU?Z wrote:
IMHO, std::pair default ctor should be defined as
pair():first(),second(){}
This doesn't change things. pair() {} is what you probably want.
Why? (This is not a rethoric question, my understanding of value-initialization matters is so poor.)
Never mind, I probably didn't understand your intent. The above does indeed eliminate the problem with the iterator while still leaving PODs zero-initialized. pair() {} will leave PODs uninitialized.
I think there's some value in having iterators being DefaultConstructible. Otherwise you're forced to have some container around everytime you construct an iterator.
I think that this is not that restrictive as it sounds, because an iterator logically belongs to a container; it has no value on its own. A single containerless iterator can be replaced by a pointer. An iterator range is, of course, useful on its own, but you can't create a containerless range, even an empty one, because...
Defaut construction for iterators is roughly the equivalent of initializing to 0 in the case of pointers.
... default-constructed iterators are useless. A NULL pointer is copyable and you can compare a NULL to another pointer, with well-defined results (so you can make an empty range from two NULL pointers). Default construction for iterators is a trap. :-)
participants (2)
-
JOAQUIN LOPEZ MU?Z
-
Peter Dimov