2017-03-06 2 views
0

for_each()の有効な発現を下回っているは構文的に正しいC++発現for_each(V、[](文字列x)は

for_each(v,[](string x){ 
    cout<<x<<endl; 
}); 

文献:?CppCoreGuidelines.md#p3-express-intent

上記式は、エラーの下スロー:

error: no matching function for call to ‘for_each(std::vector<std::__cxx11::basic_string<char> >&, 
main()::<lambda(std::__cxx11::string)>)’ 
    }); 
    ^
In file included from /usr/include/c++/5/algorithm:62:0, 
       from test.cpp:4: 
/usr/include/c++/5/bits/stl_algo.h:3761:5: note: candidate: template<class _IIter, class _Funct> _Funct std::for_each(_IIter, 
_IIter, _Funct) 
    for_each(_InputIterator __first, _InputIterator __last, _Function __f) 
    ^
/usr/include/c++/5/bits/stl_algo.h:3761:5: note: template argument deduction/substitution failed: 
test.cpp:60:6: note: deduced conflicting types for parameter ‘_IIter’ (‘std::vector<std::__cxx11::basic_string<char> >’ and 
‘main()::<lambda(std::__cxx11::string)>’) 
    }); 
+0

いや、それはない..です – DeiDei

+0

彼らが使用することができます(http [TS範囲]:/を/en.cppreference.com/w/cpp/experimental/ranges) 'for_each'。 – NathanOliver

+0

あなたのコードを詳しく説明できますか?それはあいまいだ。 –

答えて

3

まあ、コアガイドラインはfor_each、ないstd::for_each言及。それは、あなたの質問に答えるのは難しいので...

  • 、彼らが実際にstd::for_eachを参照している場合、それは2回の反復子を必要として、それは、タイプミスだろう - 彼らはstd::for_each that might be introduced with the Ranges proposalsの将来のバージョンに言及している場合を除き。

  • 彼らはそれは単に可能性があり、一般的なfor_eachを参照している場合:

    template <typename TContainer, typename TF> 
    void for_each(TContainer&& c, TF&& f) 
    { 
        for(auto&& x : c) f(x); 
    } 
    
関連する問題