You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pfultz2 edited this page Jul 30, 2012
·
3 revisions
Linq inside polymorphic function
Unfortunately, because of weakness in the type deduction of C++(hopefully there is a workaround for this soon), you can't return Linq queries from a polymorphic function. A simple example, is say we want to write a function that squares every number in a range that is positive, and we want to return this, have it all evaluated lazily with no copies.
This is because Linq uses lambdas, and lambdas can't appear inside of decltype. If we make are square_pos function only work for a vector<int> then we can use a lambda to deduce the return type: