Question

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

error: ‘result_of’ in namespace ‘std’ does not name a type

(g++ version 4.5.0 on SUSE.)

The relevant piece of code, sufficient for reproducing 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); }
};

Moreover, I have tried to compile examples from wikipedia or cpluplus.com to no avail. Is it a problem with the particular compiler or am I doing something wrong?

Was it helpful?

Solution

Try to include <functional> also. 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 move was introduced in n3090 (2010 March 29) after fixing issue 1270. gcc 4.5.0 was released just 16 days after the change (2010 April 14), which did not have enough time to apply, as we can see from this online source code of <functional>.

std::result_of was moved to <type_traits> in gcc 4.6.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top