argument dependent lookup

M

Martin Vorbrodt

simple program:

#include <iostream>
int main() {
std::cout << "bleee" << endl;
}

both VC++.NET 2003 and GCC (3.3 i think) tell me that endl is an undefined
identivier. is that correct, or should endl be visible through ADL?

thanks,
martin
 
A

Alf P. Steinbach

* Martin Vorbrodt:
simple program:

#include <iostream>
int main() {
std::cout << "bleee" << endl;
}

both VC++.NET 2003 and GCC (3.3 i think) tell me that endl is an undefined
identivier. is that correct, or should endl be visible through ADL?

Interesting, and I don't know.

Datum: fails to compile also with Comeau online, also with <ostream> included.
 
R

Razzer

Martin said:
simple program:

#include <iostream>
int main() {
std::cout << "bleee" << endl;
}

both VC++.NET 2003 and GCC (3.3 i think) tell me that endl is an undefined
identivier. is that correct, or should endl be visible through ADL?

thanks,
martin

I'm pretty sure that is correct. The overloaded operator call in the
case of endl is a member function, so ADL shouldn't apply.
 
M

Mogens Heller Jensen

Martin Vorbrodt said:
simple program:

#include <iostream>
int main() {
std::cout << "bleee" << endl;
}

both VC++.NET 2003 and GCC (3.3 i think) tell me that endl is an undefined
identivier. is that correct, or should endl be visible through ADL?

thanks,
martin

When you write std:: in front of cout, what could you possibly be missing in
front of endl?

;o)

You could of course bring in the whole namespace instead by doing a

using namespace std;

at the top.

Best regards,
Mogens
 
M

Martin Vorbrodt

aha, so maybe i'll write std:: in front of the << operator too?
std::eek:perator<<(cout, "bleee");

that's not the point. operator << is not prequalified with std:: yet it is
visible in the expression. so i wonder why endl isn't.
 
A

Alf P. Steinbach

* Alf P. Steinbach:
* Martin Vorbrodt:

Interesting, and I don't know.

Datum: fails to compile also with Comeau online, also with <ostream> included.

Bang. "<<" is a call. "endl" is just an argument. Argument-dependent lookup
uses arguments to find functions (or operators), not opposite. QED.
 
M

Mogens Heller Jensen

Martin Vorbrodt said:
aha, so maybe i'll write std:: in front of the << operator too?
std::eek:perator<<(cout, "bleee");

that's not the point. operator << is not prequalified with std:: yet it is
visible in the expression. so i wonder why endl isn't.

No, what I meant was this:
std::cout << " like this-> " << std::endl;

Operators like << are functions whose namespace and class are resolved
implicitly by the context. If you had defined a class Matrix in some
namespace called MyMath, you would automagically have the
MyMath::Matrix::eek:perator++ called if you do this:

MyMath::Matrix m;
m++;

Otherwise the syntax would be pretty funky: m(MyMath::Matrix++); or
something :eek:)
 
A

Alf P. Steinbach

* Martin Vorbrodt:
endl is an argument, not a function. makes sense. thank you

Uh, well, endl is also a function, but in this context it's the address of
endl that's used as an argument.

Just to be a bit less imprecise.

Hth.,

- Alf
 
M

Martin Vorbrodt

Alf P. Steinbach said:
* Alf P. Steinbach: included.

Bang. "<<" is a call. "endl" is just an argument. Argument-dependent lookup
uses arguments to find functions (or operators), not opposite. QED.

endl is an argument, not a function. makes sense. thank you
 
M

Mike Wahler

Martin Vorbrodt said:
aha, so maybe i'll write std:: in front of the << operator too?
std::eek:perator<<(cout, "bleee");

that's not the point. operator << is not prequalified with std:: yet it is
visible in the expression. so i wonder why endl isn't.

'std::endl' is only guaranteed to be declared by <ostream>

#include-ing <iostream> will indirectly declare 'std::endl'
on some implementations, but you can't depend upon it.

-Mike
 
M

Marcus Kwok

Mike Wahler said:
'std::endl' is only guaranteed to be declared by <ostream>

#include-ing <iostream> will indirectly declare 'std::endl'
on some implementations, but you can't depend upon it.

This is a perfect example of what I was thinking about in my thread
"Header file analyzer?".
 
D

Default User

Mike said:
'std::endl' is only guaranteed to be declared by <ostream>

#include-ing <iostream> will indirectly declare 'std::endl'
on some implementations, but you can't depend upon it.

That was more or less an oversight by the standard committee, no one
intended for that to be the case. In fact all the examples in the
standard (while not normative) use std::endl without including
<ostream>.

Are you aware of any implementations that require it?




Brian
 
M

Mike Wahler

Default User said:
That was more or less an oversight by the standard committee, no one
intended for that to be the case.

Yes, I've heard that before.
In fact all the examples in the
standard (while not normative) use std::endl without including
<ostream>.
Yes.


Are you aware of any implementations that require it?

No, but going by 'letter of the law', since the only defined
declaration of 'std::endl' in the standard is in <ostream>,
I would expect that any conforming implementation would
only be required to guarantee the declaration if that
header were included. It's just a question of writing
to the ISO standard or the 'de-facto' one(s). :)

-Mike
 
D

Default User

Mike said:
Yes, I've heard that before.

It didn't seem like it was addressed in the 2003 update to the
Standard. I originally heard from Dr. Stroustrup about it in when I
queried him in 2002 about this.

He still has an entry on his errata page for TC++PL on the matter.



Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top