Subject: Re: [boost] [uuid] Interface
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2008-12-19 14:52:38
On Fri, Dec 19, 2008 at 12:47, OvermindDL1 <overminddl1_at_[hidden]> wrote:
>> The behavior of the default constructor that you'd like to see (apologies if I got it wrong) is to create an invalid uuid. I feel that is not the canonical use of the default constructor. Indeed, that usage of the default constructor *not* to actually create an object has become quite popular. It does not make it right though. I find it unfortunate and hackish.
> I agree. I like things to either default construct with a full usable
> object, or to not be able to default construct it at all.
What defines "fully usable"? All the member functions in a nil UUID
return reasonable, predictable results, and none throw exceptions.
Do you have some examples of other objects that do (or should) behave
similarly to your desire for uuid? In my view, a uuid is essentially
a pointer (though the dereference operation is context-dependant), so
it should be null/nil by default until you define what it should be
Take, for example, a map<string, uuid>. No default constructor means
that you can't use operator, and one that generates a random uuid
means you lose the convenient semantics of a non-existant element
being equivalent to the (trivially) invalid one. (I say "trivially"
because afaik most uses of uuid do allow you to check whether a uuid
points to something or if it's garbage, though not terribly quickly or
I'm also not the only person that thinks default-constructed instances
should be equal. Take something as reasonable as
vector<uuid> v; v.resize(10);
In C++03, that resize call was specified (through a default argument)
to be equivalent to v.resize(10, uuid());. In C++0x (draft n2798),
however, it's (presumably for optimization reasons) a separate
overload from the 2-parameter version, and is specifed to, in this
case, "append  default-constructed elements to the sequence".
Given the apparent implemenation of that is to placement
default-construct them, it'd give a different result from the C++03
version if uuid() returned something random.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk