マークされたコンパイラ エラー (C2899) が表示されるのはなぜですか? VS2010 SP1でやってみました。
#include <list>
#include <vector>
#include <algorithm>
template <typename source_container_type, typename target_container_type>
void copy_all(const source_container_type& source, target_container_type& target)
{
std::for_each(begin(source), end(source), [&] (const typename source_container_type::value_type& element)
{
// error C2899: typename cannot be used outside a template declaration
// error C2653: 'target_container_type' : is not a class or namespace name
target.push_back(typename target_container_type::value_type(element));
});
}
int main()
{
std::vector<int> a;
a.push_back(23);
a.push_back(24);
a.push_back(25);
std::list<int> b;
copy_all(a, b);
}
よろしく
サイモン
PS: で使用できることはわかってstd::copy(..)
いますstd::back_inserter(..)
が、それは重要ではありません。
編集
質問は perreal のコメントで回答されました: http://connect.microsoft.com/VisualStudio/feedback/details/694857/bug-in-lambda-expressions
編集
回避策には興味がないことに注意してください。上記のコードがコンパイルされるかどうかを知りたいです。