Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-02-16 07:48:21


Fred Bertsch <fred.bertsch_at_[hidden]> writes:

> Ion is proposing a solution that solves many of the problems with a
> two stage construction process. It is still possible to use the
> constructors with std::no_throw and get an invalid state. I shouldn't
> comment on the no-exceptions, embedded world that Ion is hoping to
> placate with his strategy, but in the world where exceptions are
> possible, it should be easy to tell that you're tripping over
> something nasty when you pass std::no_throw into a constructor.

But it's not possible to tell is that someone has passed you something
nasty when somebody else uses no_throw and you're just getting a
reference to the object. That's my whole point. Strong invariants
make it possible to develop code separately without adding lots of
nasty preconditions everywhere to "ensure" that nobody has given you
something nasty.

> It seems to me that this should be good enough even if it's not
> ideal.

It's not really much better than having a default ctor that doesn't
initialize the object. The problem doesn't occur at the point of
construction; it occurs everywhere else in the program. If you make
it easy for the guy doing construction to use a 2-phase approach, you
make reasoning about code much more difficult for everyone else, and
you either complicate their preconditions or you force them into
checking for initialization and throwing exceptions. It's a mess.

> Because the topic generated some controversy, I'm hoping to get a few
> people who complained about the two stage construction to comment on
> the proposed solution before the review ends.

Well, I hope that helps.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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