Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   argument dependent lookup (http://www.velocityreviews.com/forums/t449340-argument-dependent-lookup.html)

Martin Vorbrodt 10-25-2005 04:05 PM

argument dependent lookup
 
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



Alf P. Steinbach 10-25-2005 04:27 PM

Re: argument dependent lookup
 
* 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.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Razzer 10-25-2005 04:44 PM

Re: argument dependent lookup
 

Martin Vorbrodt wrote:
> 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.


Mogens Heller Jensen 10-25-2005 04:51 PM

Re: argument dependent lookup
 

"Martin Vorbrodt" <mvorbrodt@poczta.onet.pl> wrote in message
news:djlkuk$kg5$1@news.onet.pl...
> 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



Martin Vorbrodt 10-25-2005 05:20 PM

Re: argument dependent lookup
 
aha, so maybe i'll write std:: in front of the << operator too?
std::operator<<(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.



"Mogens Heller Jensen" <mogens@mookid.dk> wrote in message
news:435e62ae$0$9303$ba624c82@nntp02.dk.telia.net. ..
>
> "Martin Vorbrodt" <mvorbrodt@poczta.onet.pl> wrote in message
> news:djlkuk$kg5$1@news.onet.pl...
> > 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
>
>




Alf P. Steinbach 10-25-2005 05:28 PM

Re: argument dependent lookup
 
* 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.


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

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Mogens Heller Jensen 10-25-2005 06:08 PM

Re: argument dependent lookup
 
> "Mogens Heller Jensen" <mogens@mookid.dk> wrote in message
> news:435e62ae$0$9303$ba624c82@nntp02.dk.telia.net. ..
>>
>> "Martin Vorbrodt" <mvorbrodt@poczta.onet.pl> wrote in message
>> news:djlkuk$kg5$1@news.onet.pl...
>> > 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
>>
>>

>
>



"Martin Vorbrodt" <mvorbrodt@poczta.onet.pl> wrote in message
news:djlpaj$4c6$1@news.onet.pl...
> aha, so maybe i'll write std:: in front of the << operator too?
> std::operator<<(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::operator++ called if you do this:

MyMath::Matrix m;
m++;

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



Alf P. Steinbach 10-25-2005 07:15 PM

Re: argument dependent lookup
 
* 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

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Martin Vorbrodt 10-25-2005 07:16 PM

Re: argument dependent lookup
 
"Alf P. Steinbach" <alfps@start.no> wrote in message
news:435e69f6.706887468@news.individual.net...
> * 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.
>
> 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


>
> --
> A: Because it messes up the order in which people normally read text.
> Q: Why is it such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?




Mike Wahler 10-25-2005 07:42 PM

Re: argument dependent lookup
 

"Martin Vorbrodt" <mvorbrodt@poczta.onet.pl> wrote in message
news:djlpaj$4c6$1@news.onet.pl...
> aha, so maybe i'll write std:: in front of the << operator too?
> std::operator<<(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




All times are GMT. The time now is 02:28 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.