473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

variant template

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

Feb 5 '06 #1
1 1815
Flash Gordon wrote:
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

Feb 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Matt Smith | last post by:
Hi, all. Just a quick question, when setting a COM process to read a value from a pre-defined register index, I think, I have to change the variable that the value will be returned to (as I have...
0
by: Matt Smith | last post by:
Hi, all. Just a quick question, when setting a COM process to read a value from a pre-defined register index, I think, I have to change the variable that the value will be returned to (as I have...
1
by: The Eternal Squire | last post by:
Hi everyone, I am wanting to write a Python COM server with a data member created by using the new Python 2.3 property() built-in function. When I attempt to access the member through a...
2
by: Thilanga | last post by:
Hi, I want to access a VARIANT array returned by a method in VC++, that is supposed to be a long array. Can anybody suggest me a way of access this array and get the values in it. ...
13
by: Dennis Lubert | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi people, I want to create my own variant of a cout Object, so that I can use different of those for debugging... Like this class, but as a...
19
by: Jon Davis | last post by:
Hi guys! Just wanted to let you all know that I created a Variant structure, inspired by the old VB6 days. This is written in C#, but you can build a CLR/.NET class library assembly and reference...
1
by: morten | last post by:
When i compile this code in VC71 or VC80 i get the following errors: The code is copy/paste from the boost.org tutorial. Please help! error C2039: 'begin' : is not a member of...
1
by: werasm | last post by:
Hi all, Traditionally the prototype pattern (cloning) causes the "cloned" to be copied. Is there an idiom where the method performing the creation creates the default type (without cloning)....
8
by: puzzlecracker | last post by:
The statement is taken from FAQ . What about non-virtual functions? Can they be overriden? I still don't see a good justification to prefer private inheritance over composition. In fact, I have...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.