C++/CLI で LINQ

(id:NyaRuRu:20050921:p5) でちょろっと書いたアイディア.
コンパイル環境は Visual C++ 2005 beta2 日本語版にて.
LINQ Project PDC 2005 Tech Preview 付属の System.Query.dll を参照設定に加えること.

#include "query.h"

using namespace System;
using namespace System::Collections::Generic;
using namespace System::Drawing;
using namespace System::Query;

static int CalcLength(Point p)
{
    return p.X * p.X + p.Y * p.Y;
}

static bool Filter(Point p)
{
    return p.X % 2 == 0;
}

int main()
{
    List<Point>^ source = gcnew List<Point>();

    for( int i = 0; i < 20; ++i )
    {
        source->Add( Point(i,i*2) );
    }

    Func<Point,bool>^ pred1 = gcnew Func<Point,bool>(Filter);
    Func<Point,int>^  pred2 = gcnew Func<Point,int>(CalcLength);

    for each( int i in
        source >> Where( pred1 ) >> Select( pred2 ) >> Reverse<int>() >> Take<int>(5) )
    {
        Console::WriteLine( "{0}", i );
    }
    
    return 0;
}

boost::lambda とかを作れる人が "query.h" を書き換えればもうちょい色々見栄えが良くなるんじゃないかと思います.