C ++ error std :: result_of does not name type

After g++ -std=c++0x 'ing std::result_of , the following error message appears

 error: 'result_of' in namespace 'std' does not name a type 

(g ++ version 4.5.0 on SUSE.)

The corresponding piece of code sufficient to reproduce the error is below

 #include <random> #include <type_traits> using namespace std; class Rnd{ protected: static default_random_engine generator_; }; template<class distribution> class Distr: Rnd{ distribution distribution_; public: typename std::result_of<distribution(default_random_engine)>::type operator() (){ return distribution_(default_random_engine); } }; 

In addition, I tried to compile examples from wikipedia or cpluplus.com to no avail. Is this a problem with a specific compiler or am I doing something wrong?

+6
source share
1 answer

Try turning on <functional> . gcc 4.5 is based on an older version of C ++ 11, in which std::result_of is defined in <functional> instead of <type_traits> .

This step was introduced in n3090 (2010 March 29) after fixing issue 1270 . gcc 4.5.0 was released 16 days after the change (April 14, 2010) , which did not have enough time to apply, as we can see from this online source code <functional> .

std::result_of been ported to <type_traits> in gcc 4.6 .

+7
source

Source: https://habr.com/ru/post/926852/


All Articles