|
Boost Users : |
Subject: Re: [Boost-users] [variant][any] template parameterized variant
From: Alfredo Correa (alfredo.correa_at_[hidden])
Date: 2010-10-09 15:23:01
On Sat, Oct 9, 2010 at 5:52 AM, Mathias Gaunard
<mathias.gaunard_at_[hidden]> wrote:
> 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.
ok, thanks for the tip. It seem that something like boost::any is the way to go.
It will be a special type of the type erasure because holded type always has the
the same sizeof. Therefore, ideally, it is a type erasure with no
necessity of dynamic allocation.
Does anybody knows a good reference or some Boost facility to
implement type erasure to start with?
I found this:
http://www.codeproject.com/KB/cpp/dynamic_typing.aspx
although it eliminates some dynamic allocation (by recycling memory
when possible) it doesn't remove it completely.
Thank you,
Alfredo
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
> --
> Sie haben diese Nachricht erhalten, da Sie der Google Groups-Gruppe Boost
> Users beigetreten sind.
> Wenn Sie Nachrichten in dieser Gruppe posten möchten, senden Sie eine E-Mail
> an boostusers_at_googlegroups.com.
> Wenn Sie aus dieser Gruppe austreten möchten, senden Sie eine E-Mail an
> boostusers+unsubscribe_at_googlegroups.com.
> Besuchen Sie die Gruppe unter
> http://groups.google.com/group/boostusers?hl=de, um weitere Optionen zu
> erhalten.
>
>
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