[variant][any] template parameterized variant
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
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
, 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.
On Sat, Oct 9, 2010 at 5:52 AM, Mathias Gaunard
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
, 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@lists.boost.org 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@googlegroups.com. Wenn Sie aus dieser Gruppe austreten möchten, senden Sie eine E-Mail an boostusers+unsubscribe@googlegroups.com. Besuchen Sie die Gruppe unter http://groups.google.com/group/boostusers?hl=de, um weitere Optionen zu erhalten.
participants (4)
-
alfC
-
Alfredo Correa
-
Igor R
-
Mathias Gaunard