argument dependent lookup

Discussion in 'C++' started by Martin Vorbrodt, Oct 25, 2005.

  1. 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
    Martin Vorbrodt, Oct 25, 2005
    #1
    1. Advertising

  2. * 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?
    Alf P. Steinbach, Oct 25, 2005
    #2
    1. Advertising

  3. Martin Vorbrodt

    Razzer Guest

    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.
    Razzer, Oct 25, 2005
    #3
  4. "Martin Vorbrodt" <> wrote in message
    news:djlkuk$kg5$...
    > 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
    Mogens Heller Jensen, Oct 25, 2005
    #4
  5. 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.



    "Mogens Heller Jensen" <> wrote in message
    news:435e62ae$0$9303$...
    >
    > "Martin Vorbrodt" <> wrote in message
    > news:djlkuk$kg5$...
    > > 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, Oct 25, 2005
    #5
  6. * 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?
    Alf P. Steinbach, Oct 25, 2005
    #6
  7. > "Mogens Heller Jensen" <> wrote in message
    > news:435e62ae$0$9303$...
    >>
    >> "Martin Vorbrodt" <> wrote in message
    >> news:djlkuk$kg5$...
    >> > 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" <> wrote in message
    news:djlpaj$4c6$...
    > 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:)
    Mogens Heller Jensen, Oct 25, 2005
    #7
  8. * 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?
    Alf P. Steinbach, Oct 25, 2005
    #8
  9. "Alf P. Steinbach" <> wrote in message
    news:...
    > * 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?
    Martin Vorbrodt, Oct 25, 2005
    #9
  10. Martin Vorbrodt

    Mike Wahler Guest

    "Martin Vorbrodt" <> wrote in message
    news:djlpaj$4c6$...
    > 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
    Mike Wahler, Oct 25, 2005
    #10
  11. Martin Vorbrodt

    Marcus Kwok Guest

    Mike Wahler <> wrote:
    > '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?".

    --
    Marcus Kwok
    Marcus Kwok, Oct 25, 2005
    #11
  12. Martin Vorbrodt

    Default User Guest

    Mike Wahler wrote:

    >
    > "Martin Vorbrodt" <> wrote in message
    > news:djlpaj$4c6$...
    > > 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.


    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

    --
    Please quote enough of the previous message for context. To do so from
    Google, click "show options" and use the Reply shown in the expanded
    header.
    Default User, Oct 25, 2005
    #12
  13. Martin Vorbrodt

    Mike Wahler Guest

    "Default User" <> wrote in message
    news:...
    > Mike Wahler wrote:
    >
    >>
    >> "Martin Vorbrodt" <> wrote in message
    >> news:djlpaj$4c6$...
    >> > 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.

    >
    > 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
    Mike Wahler, Oct 25, 2005
    #13
  14. Martin Vorbrodt

    Default User Guest

    Mike Wahler wrote:

    >
    > "Default User" <> wrote in message
    > news:...


    > > 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.


    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
    Default User, Oct 25, 2005
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. siddhu

    Argument-Dependent Lookup

    siddhu, May 14, 2007, in forum: C++
    Replies:
    1
    Views:
    353
    Old Wolf
    May 14, 2007
  2. siddhu

    Argument-Dependent Lookup

    siddhu, May 14, 2007, in forum: C++
    Replies:
    4
    Views:
    481
    James Kanze
    May 15, 2007
  3. Belebele
    Replies:
    6
    Views:
    432
    Belebele
    Dec 11, 2007
  4. Replies:
    2
    Views:
    444
    Balog Pal
    Apr 9, 2009
  5. neverhoodboy
    Replies:
    1
    Views:
    449
    Johannes Schaub
    Mar 4, 2012
Loading...

Share This Page