|
Boost Users : |
From: Christian Henning (chhenning_at_[hidden])
Date: 2005-10-10 13:22:12
typeid() gives you a reference to a type_info object. Here you could
ask for the typename name() and using a map<string, int> you could use
a switch statement. This is very slow since the string lookup, but it
works.
Another solution would be a thin wrapper class around all of your
types that has a static int member and pointer to the real object.
Here, you simply use the static and in the switch statement.
I don't know if there is more boost-like way available? Perhaps
someone else will have a higher performance and cleaner solution.
Christian
On 10/10/05, Piyush Kapadia <piyush.kapadia_at_[hidden]> wrote:
> True that I just need limited type supported and not entire universe of
> types, I have also seen following, but it would mean to put it in series of
> if(is_int), elseif(is_char_ptr) kind of statements, switch statement would
> be more cleaner, that why I thought type_traits may offer cleaner solution.
>
> Performance is also criteria.
>
>
> On 10/10/05, Christian Henning <chhenning_at_[hidden]> wrote:
> >
> > I took a look at the examples in the Boost::Any documentation and found
> this:
> >
> > bool is_int(const boost::any & operand)
> > {
> > return operand.type() == typeid(int);
> > }
> >
> > bool is_char_ptr(const boost::any & operand)
> > {
> > try
> > {
> > any_cast<const char *>(operand);
> > return true;
> > }
> > catch(const boost::bad_any_cast &)
> > {
> > return false;
> > }
> > }
> >
> > bool is_string(const boost::any & operand)
> > {
> > return any_cast<std::string>(&operand);
> > }
> >
> >
> > Is that what you're looking for?
> >
> > Christian
> >
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
> >
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net