From Python to c++

Ames Andreas Andreas.Ames at comergo.com
Wed Mar 22 05:59:15 EST 2006


Hello Marco, 

> -----Original Message-----
> From: python-list-bounces+andreas.ames=comergo.com at python.org 
> [mailto:python-list-bounces+andreas.ames=comergo.com at python.or
> g] On Behalf Of Marco Aschwanden
> Sent: Tuesday, March 21, 2006 8:43 PM
> Subject: From Python to c++
> 
> parsed = {
>   "name":["Mac", "Mike"],
>   "age":[25, 55],
>   "place":["Zurich", "Oslo"]
> }
> 
> map<string, vector<???> >
> 
> I want to build the map of lists dynamically - it can have 
> many fields or  
> just one... and I would like to have simple interface (as 
> Python offers).


If you can predetermine the possible types of the data fields at compile time (I don't know how to avoid this constraint anyway because you need to convert the string data to the field types, as well in Python as in C++) you could use:

std::map< std::string, boost::variant< std::string, int, bool > > parsed;

if your predetermined types are string, int, bool.

For more info, see http://www.boost.org/.


HTH,

aa

-- 
Andreas Ames | Programmer | Comergo GmbH |
Voice:  +49 69 7505 3213 | ames AT avaya . com



More information about the Python-list mailing list