In this tutorial they state:
A strong reason to use generic lambdas is for visiting syntax.
boost::variant<int, double> value; apply_visitor(value, [&](auto&& e){ std::cout << e; });
Here we are visiting in a polymorphic manner; but in other contexts, the names of the type we are passing isn't interesting:
mutex_wrapped<std::ostream&> os = std::cout; os.write([&](auto&& os){ os << "hello world\n"; });
Repeating the type of std::ostream& is noise here; it would be like having to mention the type of a variable every time you use it. Here we are creating a visitor, but no a polymorphic one; auto is used for the same reason you might use auto in a for(:) loop.
First of all I could not get the above example to work with out swapping the operands around:
boost::variant<int, double> value;
boost::apply_visitor(
[&](auto&& e){
std::cout << e;
},
value
);
I suppose this could be due to changes to boost since the tutorial was written.
But for the second example I cannot yet find from where mutex_wrapped
comes, and I do not understand what write(lambda)
will do, it seems to me that write()
requires const char* s, streamsize n
.
Is this second example purely imaginary as in mutex_wrapped is an imaginary class that has a write method that takes a lambda and executes the lambda using the wrapped stream as the parameter?