Subject: Re: [boost] [review] string convert
From: Vladimir Batov (vbatov_at_[hidden])
Date: 2011-05-06 19:46:55
> From: "Jeremy Maitin-Shepard" <jeremy_at_[hidden]>
> The fact that built-in types in C++ have a special "uninitialized" state
> separate from the default constructed state necessary makes them a special
> case. Nonetheless, a default constructor is often useful even if it
> serves to create an arbitrary initial state with only the guarantee that
> it won't leak memory, etc.
In my nick of the woods that is not a sufficient guarantee. That requires
*all* the code dealing with the relevant object to have checks if that
object indeed has been constructed properly and has value or it just "won't
leak memory". That is a case similar to pointers vs. references debate.
> Basically it allows the type to serve as its own optional<>, with the
> caveat that you cannot check if it has been initialized and don't need to
> dereference it explicitly.
When I need optional<>, I'll use optional<>.
> This often is more convenient/leads to better syntax that having to use
> optional<> or a smart pointer of some type everywhere.
I disagree. In my view it leads to avoidable and error-prone code where I
forget to check if the passed-in object has, in-fact, a valid state and
proceed using it.
> For instance, arrays (and some other containers) require a default
I knew containers will come up as an example sooner and later. An empty
container is a valid object in a useble state. There is nothing optional
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk