C++でLINQ的なもの - Ix++ Rx++
暇つぶしにネットサーフィンしてたらこんなのみつけた
#include <cpplinq/linq.hpp> #include <iostream> #include <vector> int main() { using namespace cpplinq; std::vector<int> v = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; auto data_parsed = from( v ) .where( []( const int i ) { return i % 2 == 0; } ) .to_vector(); for( auto&& x : data_parsed ) { std::cout << x << std::endl; } }
// 実行結果 0 2 4 6 8
こんな感じでかけるっぽい。見つけただけでまだあんまり遊んでないから、サンプルだけ。
多分、Boost.RangeやらOvenやら使えって言われる。
【追記】2012/11/17 Sat.
とあるC#erの方に、LINQはYield/拡張メソッドありきだしOven使ったほうがいいと思うと言われたのでやっぱりOven使いましょう。
やっぱりライブラリ自体にコレジャナイ感があるらしい。