Subject: Re: [boost] [optional] generates unnessesary code for trivial types
From: paul Fultz (pfultz2_at_[hidden])
Date: 2012-02-09 15:58:48


----- Original Message ----- > From: Domagoj Saric <dsaritz_at_[hidden]> > To: boost_at_[hidden] > Cc: > Sent: Thursday, February 9, 2012 2:09 PM > Subject: Re: [boost] [optional] generates unnessesary code for trivial types > >& quot;paul Fultz"  je napisao u poruci interesnoj > grupi:1328802527.4759.YahooMailNeo_at_web112602.mail.gq1.yahoo.com... >> Actually, you could just take the optional_traits as the first parameter. > So you define >> optional<T> or optional<optional_traits<my_traits<T> > >> . Then optional would be >> specialized for optional_traits that will get the user-defined traits. > > (possibly a bit of work to still get the special trivial destructor and > assignment functionality in the specialization, but) Clever ;) Actually, you could use an optional_impl class, that always uses traits. And then when the user is not passing in their own traits you would pass in default_traits. Something like this: template<class T> class optional : public optional_impl<default_traits<T> > { //Foward constructors, and operators }; template<class Trait> class optional<optional_traits<Trait> : public optional_impl<Trait > { //Foward constructors, and operators }; Then the assign operator would forward to an assign method in the base class. Of course, this would mean that if T is trivially assignable, optional<T> would not be trivially assignable. Was that one of your goals of the original design?