Boost logo

Boost :

From: Gennadiy E. Rozental (rogeeff_at_[hidden])
Date: 2001-08-30 15:00:14


--- In boost_at_y..., Douglas Gregor <gregod_at_c...> wrote:
> On Thursday 30 August 2001 03:22, you wrote:
> > Hi, Fernando
> >
> > I spend some time overlooking this discussion and realized that
what
> > really bother me is not the extern semantic. I agree with you that
> > providing an ability to the user to write s == value and *s ==
value
> > is not very good idea. It's confusing and error prone. So external
> > semantic should be pointer-like. BUT the implementation should be
> > value-based not pointer based, to eliminate dereferensing. Here
what
> > I did. Compiled and tested on MSVC and sun workshop
>
> > class optional {
> > public :
> > typedef T value_type;
> >
> > // Constructors does not allow convertion from type T. Use
> > *optional<T> = value; instead
> > optional()
> >
> > : m_initialized( false ) {}
> [snip]
> > // Data members
> > T m_v;
> > bool m_initialized;
> > };
>
> This requires T to be DefaultConstructible, which is unnecessarily
> restrictive.
>
I realize that. This is tradeoff. It will be acceptable in most
cases - at least in original examples.

If you can't live with that I would propose add something like this:
anothey policy template parameter

template <typename T, class InstantiationPolicy =
ValueIntantiationPolicy<T> >
class optional {
    void assign( T const& t ) { m_value = t; }
private:
    T& value_helper() { return m_value; }
    InstantiationPolicy m_value;
}

template<typename T>
class ValueIntantiationPolicy {
public:
    operator T&() { return m_v; }
    void operator=( T const& arg ) { m_v = arg; }
private:
    T m_v;
}

And you could add as much other policies as you need.

Gennadiy.

> Doug


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