I am surprised that your lambda solution works with g ++. clang ++ complaints using
error: variable 'out_' declared with deduced type 'auto' cannot appear in its own initializer
return out_ ;
^
I suspect that this is the correct clang ++ refusing your code (and the wrong g ++ accepting it), but I'm not sure.
Anyway, I find the idea that lambda is getting interesting.
- ( , ) operator()
.
struct outS
{
template <typename T>
outS const & operator() (T const & t) const
{
std::cout << t;
return *this;
}
};
, , ,
outS{}("Hello ")("from ")("GCC ")(__VERSION__)(" !");
std::endl
.
, std::endl
(. CPP)
template< class CharT, class Traits >
std::basic_ostream<CharT, Traits>& endl( std::basic_ostream<CharT, Traits>& os );
std::endl
.
std::cout << std::endl;
std::wcout << std::endl;
<<
std::endl
; outS
outS{}(std::endl);
outS
std::endl
.
, ; std::endl
std::cout
, std::endl
char
std::char_traits<char>
.
, (, )
outS{}(std::endl<char, std::char_traits<char>>);
struct
(outS
), endl()
outS const & endl () const
{
std::cout << std::endl;
return *this;
}
outS{}.endl();
#include <iostream>
struct outS
{
template <typename T>
outS const & operator() (T const & t) const
{
std::cout << t;
return *this;
}
outS const & endl () const
{
std::cout << std::endl;
return *this;
}
};
int main()
{
outS{}("Hello ")("from ")("GCC ")(__VERSION__)(" !").endl();
}