$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] [optional] Specializing optional to save space
From: Sam Kellett (samkellett_at_[hidden])
Date: 2015-09-28 17:50:33
> > Andrzej posted another thread about creating a new compact_optional
> class.
> > The goal of this class is to make it easy to create a new optional type
> > with a special sentinel value. This allows easy customization per
> instance
> > of an optional value.
> >
> > This post is about the opposite approach: making it easier to specialize
> > optional to provide special behavior for all instances of a given
> optional
> > type.
> >
>
> I think this is a great idea; the fact that generic code will get the
> optimized version automatically is a strength, not a weakness, of this
> approach. It is critical, though, that the behavior is indeed identical in
> all respects to the unspecialized version, so that it is a pure
> optimization.
>
surely this just isn't possible?
before: i have an optional<int>, a, and i set it's value to -1. assert(a)
passes.
after: i have an optional<int>, b, which uses the optimized for space
enhancement which internally uses the value -1 as it's sentinel value:
assert(b) fails.
this applies to any possible value of int -- so therefore somebody,
somewhere will have a valid int that is an optional and some purely genetic
code will get it wrong