Why i get the marked compiler error (C2899)? I tried with 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);
}
Kind regards
Simon
PS: I know i could use std::copy(..) with std::back_inserter(..) - but that's not the point.
EDIT
The question was answered in a comment by perreal: http://connect.microsoft.com/VisualStudio/feedback/details/694857/bug-in-lambda-expressions
EDIT
Please note that i'm not interested in workarounds. I want to know whether the code above should compile or not.
Your line is valid: http://ideone.com/qAF7r
Even the ancient g++ 4.3 compiles it. So it's probably a bug in your MS compiler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With