Boost logo

Boost :

From: David B. Held (dheld_at_[hidden])
Date: 2003-02-25 16:59:22

I think optional might be perfect for an issue I have, but there is one
I have a polymorphic hierarchy that I would like to use with optional, but
optional<Base> is not a base of optional<Derived>. Of course, this isn't
really a problem with optional, par se, but any suggestions on how to store
pointers to optional<T> when T is polymorphic would be appreciated.

I know I can use aggregation like so:

class Base
    virtual ~Base() { }

template <typename T>
class PolyOptional : public Base
    optional<T> value_;

and then just store Base*, but this requires explicit run-time checking of
types which would otherwise be automatic with pointers to T instead of
optional<T>. If this is the only solution, so be it; but any clever
alternatives are welcome.


Boost list run by bdawes at, gregod at, cpdaniel at, john at