c++ - typedef return type of template parameter's member function -


i'm trying typedef return type of member function of template argument. this:

template <typename t> class dosomething{     typedef return_type (t::*x)(void)const data_type;     data_type x1; }; 

in case, want typedef return type of const member function of template parameter, called x. in example return_type place holder, show want. won't compile.

edit: reason want way is: want operations on x1 or other variable of type data_type in example, same precision return type of x() member function. if x() returns float template ops in floats , on.

i found one answer on so. don't want use c++11 features. no decltype, no auto. work c++03 compiler.

this seems work (even when boost typeof forced use long way rather c++11 or compiler-specific feature):

#include <boost/utility/declval.hpp> #include <boost/typeof/typeof.hpp>  template <typename t> class dosomething {     typedef boost_typeof_tpl(boost::declval<t const&>().x()) data_type;     data_type x1; }; 

but resulting type cannot involve class, struct, union, or enum types.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -