On Thu, Mar 24, 2011 at 1:22 PM, Greg Chicares <gchicares@...> wrote:
> On 2011-03-24 16:16Z, K. Frank wrote:
> Thanks. It has already been answered there. I was staring at those
> inserters in the standard, and I should have seen the answer...
> basic_ostream<charT,traits>& operator<<(const void* p);
> template<class charT, class traits>
> basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*);
> ...which is that the free function can't bind to a non-const reference.
Yes, as far as the specific question I posted on comp.lang.c++,
it looks like this is the solid, standard-based answer.
On Thu, Mar 24, 2011 at 1:44 PM, Greg Chicares <gchicares@...> wrote:
> On 2011-03-24 17:22Z, Greg Chicares wrote:
>> But those functions are the same in C++2003, AFAICT,
I expect that g++ is largely compliant with c++2003, the current
> However, C++0x extends beyond C++2003.
>> so is 'g++ -std=c++0x' in error?
Yes, "-std=c++0x" turns on some (a lot) of the features of the of the
new c++0x draft standard. I agree that operator<< for char* is a free
function in c++0x, that is, not a member function of ostream. (I have
a copy of the draft standard, but unfortunately not a copy of the current
standard, so I have to rely on others for what the current standard says.)
So in terms of member / non-member function, we still have the same
But "-std=c++0x" might be right for another reason.
> Or does N1377
> come into play here?
Yes, maybe. I think this is similar to what Kai was saying. I haven't
yet absorbed 12.2, "Temporary objects," the section Kai referred to.
(How shall I say this? I don't always find the language of the standard
to be, well, optimally transparent.),
I'm not sure that this is directly related to move semantics, but I think
Kai is saying that the draft c++0x standard relaxes the restriction that
prevents binding a non-const reference to a temporary.
If so, then we can use the non-member operator<< for char* (by
binding to its ostream& reference argument), rather than the
member operator<< for void*. That would seem to give a consistent
explanation of what we're seeing, and g++ would be correct in
both cases (both with and without "-std=c++0x").
However, I don't think this explains the full breadth of what we are
seeing (the skipws and other variations). (I didn't ask about those
I think I will let the comp.lang.c++ thread "season" a little bit while
I try to understand the section 12.2 language about temporary
variables. Then maybe I'll try to get my ducks in a row, and post
some follow-up questions to the usenet thread.
Thanks again for your thoughts.