Questions tagged [result-of]

std::result_of is a C++11 metafunction that provides the result of calling a function type with a given set of argument types.

The class template std::result_of is defined in the C++11 standard library and is a type transformation trait i.e. a metafunction that takes one type and produces another type.

The nested type std::result_of<F(A, B, C)>::type is a typedef for the type that would be returned by the expression f(a, b, c) for a callable object f of type F and arguments of types A, B and C.

50 questions
1
vote
1 answer

c++ how to define a std::result_of that can handle R is void

When i am using std::result_of like this: template class Task { //... template auto Then(F&& f) -> Task::type(Args...)> { //... } …
D.pz
  • 161
  • 7
1
vote
2 answers

C++11: std::result_of<> template argument vs std::function<>

I did do some research on std::result_of<>, and am aware how it's used on a high level, but am still pretty confused on this magical thing. So, if I understand it correctly, the form R (Args..) should be interpreted by the compiler as a function…
Dejavu
  • 1,299
  • 14
  • 24
1
vote
1 answer

Using std::result_of<> for member method of member type

I am working with a HashMap type that does not specify its KeyType as a public member, only the ValueType. A way to retrieve the KeyType would be to use std::result_of with the HashMap<>::Entry::GetKey() method. I can't get it to work in a template…
Niklas R
  • 16,299
  • 28
  • 108
  • 203
1
vote
1 answer

get resulting type of std::bind

I'm trying to get the resulting type of std::bind in combination with a lambda. I've tried the following two: template typename std::result_of func(F f, uint i); This doesn't work for whatever reason. I've also tried…
user3617992
  • 359
  • 1
  • 8
1
vote
1 answer

no type named "type" in "std::result_of" ; get return type from overloading functions

I am learning how to get type of the return value of overloaded function test() vs test(double). I modified code from a SO answer (by chris). #include #include int test(); double test(double x); template
javaLover
  • 6,347
  • 2
  • 22
  • 67
1
vote
1 answer

Need ‘typename’ before ‘std::result_of<_Signature>::type’ because ‘std::result_of<_Signature>’ is a dependent scope

I can't any good solution. I have piece of code: #include #include #include #include #include #include #include #include #include #include…
Pingwin Tux
  • 124
  • 9
1
vote
3 answers

C++11 result_of deducing my function type failed

I was trying a program below: #include using namespace std; template ::type> R call(F& f) { return f(); } int answer() { return 42; } int main() { call(answer); return…
Troskyvs
  • 7,537
  • 7
  • 47
  • 115
1
vote
1 answer

C++11 applies result_of on member function, failed, why?

I've got the following code as an experiment: int f1() { return 0; } struct Bar { Bar() = delete; int f() { return 0; } int operator()() { return 1; } }; int main() { decltype(f1()) x = 3;//f1() is expression …
Hind Forsum
  • 9,717
  • 13
  • 63
  • 119
1
vote
1 answer

std::result_of on std::bind does not compile on clang++ 3.4

The following code compiles using g++-4.8 but it doesn't when using clang 3.4. #include #include struct A { template bool operator()( //const Continuation & continuation …
1
vote
1 answer

Workaround for VS 2013 SFINAE deficiencies

I'm trying to fix up a library (entityx) that does not currently compile on Windows using VS 2013. It compiles fine on Linux with gcc and also on Windows with MinGW. It seems the problem is with SFINAE - I guess VS 2013 doesn't properly ignore…
Jarrett
  • 1,767
  • 25
  • 47
1
vote
2 answers

Result type of a class method?

Consider the following example: #include #include #include #include // Array: I cannot modify this class template class Array { public: Array() : _data()…
Vincent
  • 57,703
  • 61
  • 205
  • 388
0
votes
1 answer

why std::result_of can't accept function type?

I have this code int f(int i){ return i; } int main(){ cout << std::boolalpha; using f_1 = decltype(f); using f_2 = decltype((f)); cout << is_same, int>::value<< endl; // ERROR cout <<…
Kevin eyeson
  • 375
  • 4
  • 8
0
votes
1 answer

std::result_of syntax kerfuffle

I have the following (CUDA) function: __device__ auto foo(my_class& x, my_function_ptr_type y ) { return [gen](my_class& x) { return x.set_y(y); }; } And I want typedef its return value's type. I've fiddling with the std::result_of syntax, and…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
0
votes
2 answers

Can I get the Return Type of a Function From a Signature?

So I have a ton of functions similar to these: template bool Zero(const T, const T, const T); template T One(const T, const T, const T, bool); template T Three(const T, const T, const T, const T, const T, const…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
0
votes
0 answers

How can I use std::result_of to return the function type instead of void

I am trying to get the return type of a function that I bind in. In this instance I was expecting to see the return type of GetFactorialResult (int). #include #include #include namespace { const…
Jon
  • 1
  • 1