
"Andy Little" <andy@servocomm.freeserve.co.uk> wrote in message news:bvnupa$h14$1@sea.gmane.org...
Though perhaps this might work:
result_of<myClass, '+' , myClass>::type t = x+y; or result_of< operator_<'+'>,myClass,myClass >::type t = x + y;
maybe I'll experiment with that.
Hows about this: regards Andy Little ---------------------------- // useage // binary_result<A,op,B>::type // type is the type of the result of A op B // op represented by operators in <functional> //Alexey Gurtovois promotion header // slightly hacked #include "types_promotion_traits.hpp" #include <functional> #include <iostream> template < typename A, /// just want to reuse the name from <functional> template<typename> class Binary_operator, typename B
struct binary_result{ // usually does the right thing typedef typename boost::types_promotion_traits< A, B >::type type; };
// specialisations for comp ops template< typename A, typename B
struct binary_result< A,std::less,B
{ typedef bool type; }; // udt ops struct Dummy1{}; struct Dummy2{}; struct Dummy3{};
template<> struct binary_result< Dummy1,std::multiplies,Dummy2
{ typedef Dummy3 type; };
int main() { std::cout << typeid(binary_result< char,std::plus,char >::type).name() <<'\n'; std::cout << typeid(binary_result< float,std::multiplies,int >::type).name() <<'\n'; std::cout << typeid(binary_result< char,std::less,double >::type).name() <<'\n'; std::cout << typeid(binary_result< Dummy1,std::multiplies,Dummy2 >::type).name() <<'\n'; } /* output VC7.1: int float bool struct Dummy3 */