mrange / cpplinq

LINQ for C++ (cpplinq) is an extensible C++11 library of higher-order functions for range manipulation. cpplinq draws inspiration from LINQ for C#.
http://cpplinq.codeplex.com/
Other
183 stars 40 forks source link

select with optional index parameter #6

Open KN4CK3R opened 8 years ago

KN4CK3R commented 8 years ago

I implemented the second overload of the select operator which takes the index of the current element in the sequence.

https://msdn.microsoft.com/en-us/library/bb534869%28v=vs.110%29.aspx

Example:

std::vector<std::string> str = { "Value1", "Value2", "Value3" };
from(str)
        >> select([](auto&& s, auto&& i) { return std::make_pair(i, s); })
        >> for_each([](auto&& s) { std::cout << s.first << " = " << s.second << "\n"; });

prints

0 = Value1
1 = Value2
2 = Value3
KN4CK3R commented 8 years ago

added select_many too

srvasn commented 5 years ago

@KN4CK3R, ran into this while porting your SDK generator to ARM :)