Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples do not build #7

Closed
mgaunard opened this issue Sep 16, 2014 · 2 comments
Closed

examples do not build #7

mgaunard opened this issue Sep 16, 2014 · 2 comments

Comments

@mgaunard
Copy link

../example/foldable.cpp:30:48: error: no member named 'str' in 'std::basic_ostream<char>'
            return (std::ostringstream{} << x).str();

This is with clang 3.6.0 885f51439b619bfc42e47c70bd3404ceedcf259f on Linux.

@mgaunard
Copy link
Author

static_cast<std::ostringstream&>(std::ostringstream{} << x).str(); works well

@ldionne
Copy link
Member

ldionne commented Sep 16, 2014

Here's what I think happens: std::ostringstream{} << x returns a std::basic_ostream<char> when it is used with a std::string, because the operator<< is defined as:

template<class _CharT, class _Traits, class _Allocator>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os,
           const basic_string<_CharT, _Traits, _Allocator>& __str);

Then, we try to .str() that basic_ostream, which results in the provided error. I had never thought about the fact that operator<< would return a basic_ostream; I find that badly designed and counterintuitive. Still, I'll fix the examples.

Thanks for reporting.

ldionne added a commit that referenced this issue Sep 16, 2014
@ldionne ldionne closed this as completed Sep 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants