Boost logo

Boost Users :

Subject: Re: [Boost-users] [variant][any] template parameterized variant
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2010-10-09 08:52:36


On 08/10/2010 20:42, alfC wrote:
> Hi,
>
> I need a variant type object that can hold any type characterized by
> a template. For example Boost.Units have a family of types
> parameterized by "System".
>
> quantity< unit<dimension, System>, double>
>
> suppose dimension is fixed, e.g. typedef boost::units::length
> dimension
>
> is it possible to define a variant over that family of types?

No.

> I could
> create a make_variant_over< list of all types> but that can be that
> list will be fixed and each time I defined a new System the list will
> have to grow.

Variant can only work with a fixed list of possible types.

> Or should I be using an extension of boost::any with some adhoc
> restriction over the possible types on construction?

You could use type erasure.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net