Modern Native C++ Development for Maximum Productivity
- Date: May 19, 2011 from 8:30AM to 9:45AM
- Day 4
- DEV303
- Speakers: Kate Gregory
- 21,785 Views
- 2 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Right click “Save as…”
Slides (view online)Already have a Channel 9 account? Please sign in
Follow the Discussion
The type of prime *is* typeable. It is of type: std::function< bool(int) >
@Ferruccio
That's actually not quite right. A Lambda of the form [](int x) { return true; } is _assignable_ to std::function<bool(int)>, but that's not quite the same as saying the type of the lambda _is_ std::function<bool(int)>.
Consider:
bool function(int);
struct functor
{
bool operator()(int);
};
//...
std::function<bool(int)> f;
// I can assign a function pointer to f, is f of type bool (*)(int)?
f = &function;
// I can assign a functor to f, is f of type functor?
f = functor();
// And now a lambda
f = [](int x){ return false; };
In the above example, f is none of a function pointer, a function object, or a lambda, yet it accepts all of them just fine.
Lastly, consider:
decltype([](int x) { return false; }) x = [](int x){ return false; };
In the above, I am trying really really hard to get the correct type of the lambda so I can name the type explicitly, yet (in VS2010 anyway) that won't compile. So, it seems that indeed, the type of a lambda is untypable, even though that doesn't stop us from assigning it to std::function or doing other useful things with it.
Remove this comment
Remove this thread
close