Subject: Re: [boost] [optional] generates unnessesary code for trivial types
From: Domagoj Saric (domagoj.saric_at_[hidden])
Date: 2012-02-09 07:50:16
On 8.2.2012. 19:05, Hite, Christopher wrote:
> On Tuesday, February 07, 2012 17:00:04 Andrey Semashev wrote:
>> BTW, I would really like to see optional< T& > optimized to store T*
> I'm going to say something provacative here. I agree with Lucanus. I see no
> reason for optional<T&>. As far I can tell you could use a T*. The only
> justification I can think of is on system without memory protection you can
> build checks into operator*().
> Maybe if you're mixing code with old libraries where T* might imply ownership
> you might use optional<T&> to imply no ownership and some temporary validity.
> Perhaps we should define a new "smart pointer" called dumb_ptr<T> which can't
> be assigned into auto_ptr,unique_ptr,shared_ptr, or any pointer type which
> implies ownership.
> Maybe I'm missing something, but I don't see the justification.
IMO it seems that, yes, you are making the same mistake as Lucanus, thinking
about "The Universe" only as/through your POV of your personal problem domain:
a) (optional models optionally holding an object) + (objects can be held by
value and by reference) = optional<T&> perfectly logical
b) creating special cases (e.g. for T&) creates special problems in generic code
-- "What Huxley teaches is that in the age of advanced technology, spiritual devastation is more likely to come from an enemy with a smiling face than from one whose countenance exudes suspicion and hate." Neil Postman
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk