Boost logo

Boost :

From: Rainer Deyke (root_at_[hidden])
Date: 2001-08-29 12:24:56


It seems to me that 'optional<T>' is in many ways similar to
'scoped_ptr<T>':

 - Both are either null or contain a single object of type 'T'.
 - Both are conceptually pointers to the contained object.

Differences:

 - 'scoped_ptr<T>' can contain an object of a derived type; 'optional<T>'
cannot.
 - 'scoped_ptr<T>' keeps the contained object on the heap; 'optional<T>'
keeps it stores it directly.
 - 'scoped_ptr<T>' is initialized with an object that is already created on
the heap. This does not make sense for 'optional<T>'.

Given those similarities, I think it makes sense for the interface of
'optional<T>' to resemble the interface of 'scoped_ptr<T>' as closely as
possible. If a user of 'optional<T>' later needs to be able to contain
objects of derived types, switching to 'scoped_ptr<T>' should take a minimal
amount of effort. The same applies when a user of 'scoped_ptr<T>' who does
not need to contain objects of derived types and wants the greater
performance of 'optional<T>'.

--
Rainer Deyke (root_at_[hidden])
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

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