API を作成しようとすると、MiniGW で問題が発生します。これは、MSVC11 (Visual Studio 2012 C++ コンパイラ) では正常に機能します。私のコンパイラ(私は信じています)は適切に設定されてQMAKE_CXXFLAGS += -std=c++0x
います.結局のところ、ラムダエラーメッセージが表示されます.
いくつかの詳細については、次のとおりです。
typedef std::function<bool(Item)> WHERE;//I was attempting to provide an explicit cast, 'auto' works fine in MSVS
Group where(WHERE func);//A simple "foreach boolean" search
上記の使用->
Groups::WHERE where = [](Item & x)-> bool{return x.has("NEW");};
結果:
tst_groupstest.cpp:257: エラー: 'GroupsTest::groups()::__lambda1' から非スカラー型 'Groups::WHERE {aka std::function}' への変換で Groups::WHERE where = [](Item & x)-> bool{return x.has("NEW");};
これが明らかなものであることを願っていますが、見つけられません。このプロジェクトで将来的に Linux と Mac をサポートすることを計画しているので、遅かれ早かれこれを理解したいと思っています。
これが私の現在の回避策であり、可能な限りこれを避けたいと思います(結局のところ、ラムダを念頭に置いてAPIを設計した理由は、明白な簡潔なコードブロックを持つことでした)。
このセクションはコンパイルされます(ラムダを使用していません)
struct lambdaCueListstdFunc{
bool operator()(Groups::Item x)
{
return x.has("NEW");
}
};
/**
* Selects all cues for a particular list
* @brief getCueList
* @param list
* @return a vector of all the cues for this list sorted by number.
*/
std::vector<Groups::Item> CueService::getCueList(std::string list)
{
std::function<bool(Groups::Item)> where = lambdaCueListstdFunc();
// auto where = [&list] (Groups::Item & x) ->
// {
// return x.get(la::cues::List) == list;
// };
std::vector<Groups::Item> result = cues()->where(where).sort(la::cues::NUMBER);
return result;
}