VS2010β のC++はラムダ式をサポートしてくれよるワケだが、
ラムダ式はC++/CLIでも使えるんだろか....やってみた。
#include <cliext/vector>
#include <cliext/algorithm>
int main(){
cliext::vector<System::String^> v;
v.push_back(L"ラム");
v.push_back(L"ダっちゃ!");
cliext::for_each(v.begin(), v.end(),
[](System::String^ s) { System::Console::Write(s);});
}
結果:
error C3498: 's': you cannot capture a variable that has a managed type
→ managed型の変数をキャプチャすんなやゴルァ
だそうです ヽ(`Д´)ノウワァァァン
目下のところ、ラムダ諦めて↓こーするっきゃなさげ。
namespace {
struct print {
void operator()(System::String^ s) const {
System::Console::Write(s);
}
};
}
int main(){
cliext::vector<System::String^> v;
v.push_back(L"ラム");
v.push_back(L"ダっちゃ!");
cliext::for_each(v.begin(), v.end(), print());
}
System::Int32とか、C++native型とコンパチならば許してくれるみたいですが...
int main(){
cliext::vector<System::Int32> v;
v.push_back(123);
v.push_back(456);
cliext::for_each(v.begin(), v.end(),
[](System::Int32 n) { System::Console::Write(n);});
}
しょぼーん (´・ω・)