6

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?

ildjarn
  • 62,044
  • 9
  • 127
  • 211
user1672572
  • 321
  • 2
  • 9
  • g++ 4.6.3 doesn't complain about `result_of` (it complains about the code afterwards, however), so maybe it's just not yet implemented in your version, and you need to upgrade the compiler. – celtschk Oct 03 '12 at 15:32
  • And looking closer on your code, I also see the error g++ 4.6.3 complains about: you are passing a type instead of an object to `operator()` of the member object `distribution_` (I guess you wanted to pass `generator_`). – celtschk Oct 03 '12 at 15:39
  • @celtschk. Yes, of course, I am passing the `generator_`. Just a "typo". – user1672572 Oct 03 '12 at 15:46

1 Answers1

7

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.

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005