
2013/11/16 Mathieu Champlon <m.champlon@free.fr>
On 16/11/2013 16:58, Antony Polukhin wrote:
2013/11/16 Mathieu Champlon <m.champlon@free.fr> <...>
Do you think getting the type info of the "current" type of a variable
(as opposed to it's real type) could sometimes prove useful ? Could it be worth adding a function in TypeIndex ?
This is a very very common use case in Boost and widely used technique in libraries that use type erasure. Examples are Boost.Function, Boost.Any, Boost,Graph, Boost.Math and others... Such function is already in TypeIndex library, see boost::type_info<T>().
Yes, but I meant given :
#define SOME_MACRO_IN_MY_LIBRARY( variable ) do_something_complicated_ requiring_type_info_of_type_of_variable
I cannot use boost::type_info<T>() easily can I ? Granted I could do boost::type_info< BOOST_TYPEOF( variable ) >() but that's a bit cumbersome compared to for instance a simple boost::type_info( variable ).
Sorry, I meant boost::type_id ( http://apolukhin.github.io/type_index/boost/type_id.html) Well, usually you have the type of the variable nearby, and can use it in type_id<T>: template <class T> void operator()(const T& var) { type_id<T>(); // no need in type_id(var); } ... int i; type_id<int>() // no need in type_id(i); Cases when it is hard to detect variable type are rare in Boost and I do not really wish to produce many trivial functions and make the library heavier. Anyway, user can always write such function in half a minute: tempalte <class T> inline const boost::type_info& my_type_id(const T&) { return boost::type_id<T>(); } -- Best regards, Antony Polukhin