a.iterate([&os](unsigned i, const B& x) {
os << i << "=" << x << "\n";
});
The lambda function presented here has the effect of declaring an "unnamed" local class in the function region inside the function body operator<<. We can write our own functor object to get a similar effect:
struct lambda {
std::ostream& os;
lambda(std::ostream& os_) : os(os_) {}
void operator()(unsigned i, const B& x) {
os << i << "=" << x << "\n";
}
};
a.iterate(lambda(os));
This causes a similar error from g ++:
error: default argument for template parameter for class enclosing
‘operator<<(std::ostream&, const Foo<B>&)::lambda::lambda’
Here is the SSCCE:
template <typename T = int>
struct Foo
{
friend void f() {
struct local {};
}
};
And the error it causes is:
error: default argument for template parameter for class enclosing
‘f()::local::local’
This has already been reported as bug GCC 57775 .
@PiotrNycz, , operator<< .