Just some short questions. Are you sure you want save all the kinds of
types that are available on this planet? Or do want to save a subset
that is a countable?
On 10/9/05, Piyush Kapadia
Let's say if using - std::map
tmap; Now you can put anything in tmap, which could be primitive types or vector or another map.
Then you want to implement
ostream& operator << (ostream& os, const tmap& _map) { // Over here we need to identify - // if iterator->second is primitive type, vector, map or unknown type. // Depending up on that we can decide if we need to iterate through // another vector or simply use << for primitive type. // That's why is_primitive or other type_traits functions may help.
// Ideally we need switch statement like following switch(type(_map)) { case int : case double : case long : return os<< _map; case vector : {// interate through vector here. } .. .. // and so on.
}
}
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Christian Henning Sent: Saturday, October 08, 2005 6:10 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost::any Question
I'm not sure why you would want to use traits here. I think traits are used for compile-time if...else tests on types.
Why not use a static numerical member in classes that you put in your map and so you could use a switch statement to figure out what type you are using?
There are probably better ways to do that. RTTI ain't!
Christian
On 10/7/05, Piyush Kapadia
wrote: I am new user of Boost, I tried to use boost::variant first, but in comparison to boost::any performance of boost::variant appears to be
around
4 times slower, so settled for boost::any.
Also boost::any has cleaner interface but I don't know how to query current type information for boost::any ?
My code looks like following
map
result_table; result_table[1] = 543.434;
vector<int> vec;
.. Some vec population code;
result_table[2] = vec;
Now I need to develop a stringify function for result_table;
I can fetch the results back as
boost::any value = result_table[2];
But I need to know the type of value, so that I can treat it accordingly to stringify;
I know there exists type_traits, but very limited examples of type_traits is provided on Boost documentation and particularly, I am clueless about how to use type_traits in above context to find out what is the current type returned by result_table[int]
Also I want to know if Boost has any Hash map implementation that can be superior in performance compare to regular std::map ??
Thanks,
Piyush _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users