Boost logo

Boost :

Subject: Re: [boost] [optional] memory use for optional refs and ptrs
From: Rutger ter Borg (rutger_at_[hidden])
Date: 2010-10-06 14:31:30


On 2010-10-06 20:21, Nevin Liber wrote:
>
>> Although [references aren't] the most important case for me, it has its own section in
>> the documentation, and I will probably be using lots of these.
>
> Why? What is the advantage over using a raw pointer?
>

None at this time. It's just that an optional<T&> exactly does what
everyone usually does with null-pointers and stuff. I thought it might
be clearer and less prone to error.

>> What also
>> doesn't seem right to me is that, e.g.,
>>
>> struct A {
>> int a;
>> double b;
>> double c;
>> std::string d;
>> };
>>
>> struct B {
>> boost::optional< int> a;
>> boost::optional< double> b;
>> boost::optional< double> c;
>> boost::optional< std::string> d;
>> };
>
> What bit pattern can be used for an int which says it hasn't been set?

In this particular example I'm showing the space efficiency of different
classes (see
http://article.gmane.org/gmane.comp.lib.boost.devel/209212), I'm not
saying int should have a certain bit pattern for "unset". I'm merely
saying that due to the extra boolean and padding, sizeof(B) grows.

>
> Optional models "the variable is not set." You want something
> different. Why not just create a different class to model what you
> want?

I think I know what optional models, and it is clearly what I want.
However, I would like to have space-efficient ones.

Cheers,

Rutger


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