variant template

F

Flash Gordon

ok here is the problem: I need to have a map of variants that actually
vary *only* at initialization, i.e.

vmap["foo"] = variant<int, float>(1); // constructed as int
vmap["bar"] = variant<int, float>(2.34f); // constructed as float

vmap["foo"] = 10 * vmap["bar"]; // floating point multiplication, then
23.4f rounded to int 23
vmap["bar"] = vmap["foo"] / 2; // integer division, then 10 converted
to 10.0f

so essentially, I need a heterogenous map of primitive types

what would be the best way to implement this? I looked at
boost::variant but it doesn't seem to suit me
 
L

Luke Meyers

Flash said:
ok here is the problem: I need to have a map of variants that actually
vary *only* at initialization, i.e.

vmap["foo"] = variant<int, float>(1); // constructed as int
vmap["bar"] = variant<int, float>(2.34f); // constructed as float

vmap["foo"] = 10 * vmap["bar"]; // floating point multiplication, then
23.4f rounded to int 23
vmap["bar"] = vmap["foo"] / 2; // integer division, then 10 converted
to 10.0f

so essentially, I need a heterogenous map of primitive types

what would be the best way to implement this? I looked at
boost::variant but it doesn't seem to suit me

Perhaps a thin wrapper around boost::any would be more suitable?
Sounds like you basically just want something more restrictive, so you
can just only expose the operations you want to allow.

Luke
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top