Boost logo

Boost :

From: William E. Kempf (wekempf_at_[hidden])
Date: 2002-12-16 17:57:01


Augustus Saunders said:
> William Kempf wrote:
>>> Some people, mostly _me_, argued that this is not a good idea
>>> because code would change meaning if optional<> is replaced
>>> by a pointer.
>>
>>But it's going to change in any event, because optional<> _isn't_ a
> pointer.
>>
>>But in generic code you must follow the semantics of the concept, and
>> optional<> isn't useable when a SmartPointer concept is
>>required. Define the concept well enough, and optional<> becomes
>> useful in generic code.
>
> Hi Will, I really appreciate the comments you've been making on this
> topic, so I wanted to ask for a couple more :)
>
> 1) Fernando and I briefly went over defining an OptionalValue
> concept, of which real pointers, smart pointers, and optional would
> model (along with others, I'm sure). Is this on the right track to
> define the concept "well enough?"

*I* think so, but there's others here who are much more qualified than I
on this subject.

> 2) Presuming three things:
> a) Pointer interface is kept
> b) OptionalValue concept is well defined
> c) deep comparison is kept
> would you be at all concerned about optional compiling when misused in
> generic code that presumes different semantics for the comparison
> operator? This feels like a booby-trap to me, but I would like to know
> your and other people's opinions on this specific point.

I wouldn't be overly concerned. I'd find this to be a programmer error
(passing a type to a template that doesn't meet the template's
requirements). Concept checking libraries can even be employed to insure
such mistakes don't happen (assuming the concepts are well defined enough
for such checks to be written), though this would be a QoI issue in the
implementation of the template.

William E. Kempf


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