| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Steven T. Hatton" |
| Date: |
14 Dec 2006 07:47:09 AM |
| Object: |
What would C++ look like without ADL? |
I'll admit, so far in my C++ experience, I've left ADL to the realm
of 'magic happens'. I really don't know when I might be using it. Can
someone provide examples of how ADL changes the behavior of 'typical' code?
If it were not available, would that absence completely change the way we
use the STL or do other things?
If anybody is wondering, yes, I am curious about the ROI of having ADL in
the C++ language specification. It seems to significantly complicate the
language design, and can, at times introduce subtle anomalies which can be
hard to understand. Sometimes I see people doing fancy things with
typedefs to "prime" the ADL pump, and I wonder how much typing they are
actual avoiding, and how much cleaner the resulting code really is.
"Alles sollte so einfach wie möglich gemacht sein, aber nicht einfacher."
--
NOUN:1. Money or property bequeathed to another by will. 2. Something handed
down from an ancestor or a predecessor or from the past: a legacy of
religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/
.
|
|
| User: "Howard" |
|
| Title: Re: What would C++ look like without ADL? |
14 Dec 2006 09:38:23 AM |
|
|
"Steven T. Hatton" <chattengau@germania.sup> wrote in message
news:coednZo8sv2oyxzYnZ2dnUVZ_oWdnZ2d@speakeasy.net...
I'll admit, so far in my C++ experience, I've left ADL to the realm
of 'magic happens'. I really don't know when I might be using it. Can
someone provide examples of how ADL changes the behavior of 'typical'
code?
If it were not available, would that absence completely change the way we
use the STL or do other things?
If anybody is wondering, yes, I am curious about the ROI of having ADL in
ROI? ADL? You might consider that not everyone knows what those acronyms
mean.
the C++ language specification. It seems to significantly complicate the
language design, and can, at times introduce subtle anomalies which can be
hard to understand. Sometimes I see people doing fancy things with
typedefs to "prime" the ADL pump, and I wonder how much typing they are
actual avoiding, and how much cleaner the resulting code really is.
"Alles sollte so einfach wie mvglich gemacht sein, aber nicht einfacher."
And most of us don't speak German, either, assuming that's what that is.
.
|
|
|
| User: "F.J.K." |
|
| Title: Re: What would C++ look like without ADL? |
14 Dec 2006 10:07:00 AM |
|
|
Howard schrieb:
"Alles sollte so einfach wie mvglich gemacht sein, aber nicht einfacher."
And most of us don't speak German, either, assuming that's what that is.
A famous citation of Albert Einstein. "All should be done as easy as
possible, but not easier."
.
|
|
|
|
|
| User: "Salt_Peter" |
|
| Title: Re: What would C++ look like without ADL? |
14 Dec 2006 08:57:12 AM |
|
|
Steven T. Hatton wrote:
I'll admit, so far in my C++ experience, I've left ADL to the realm
of 'magic happens'. I really don't know when I might be using it. Can
someone provide examples of how ADL changes the behavior of 'typical' cod=
e?
If it were not available, would that absence completely change the way we
use the STL or do other things?
If anybody is wondering, yes, I am curious about the ROI of having ADL in
the C++ language specification. It seems to significantly complicate the
language design, and can, at times introduce subtle anomalies which can be
hard to understand. Sometimes I see people doing fancy things with
typedefs to "prime" the ADL pump, and I wonder how much typing they are
actual avoiding, and how much cleaner the resulting code really is.
"Alles sollte so einfach wie m=F6glich gemacht sein, aber nicht einfacher=
.."
--
#include <iostream>
#include <ostream>
#include <string>
int main()
{
std::string s("a short string");
std::cout << s << std::endl;
// std::cout.operator<<(s); error, no match
std::cout.operator<<(s.c_str()); // prints pointer
}
/*
a short string
0x502028
*/
.
|
|
|
| User: "Steven T. Hatton" |
|
| Title: Re: What would C++ look like without ADL? |
14 Dec 2006 09:05:05 AM |
|
|
Salt_Peter wrote:
#include <iostream>
#include <ostream>
#include <string>
int main()
{
std::string s("a short string");
std::cout << s << std::endl;
// std::cout.operator<<(s); error, no match
std::cout.operator<<(s.c_str()); // prints pointer
}
I'm not advocating here, but this will work:
#include <iostream>
#include <string>
int main()
{
std::string s("a short string");
std::cout << s << std::endl;
operator<<(std::cout,s);
std::endl(std::cout);
std::cout.operator<<(s.c_str()); // prints pointer
std::endl(std::cout);
}
--
NOUN:1. Money or property bequeathed to another by will. 2. Something handed
down from an ancestor or a predecessor or from the past: a legacy of
religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/
.
|
|
|
|
|
| User: "Greg" |
|
| Title: Re: What would C++ look like without ADL? |
14 Dec 2006 08:22:17 AM |
|
|
Steven T. Hatton wrote:
I'll admit, so far in my C++ experience, I've left ADL to the realm
of 'magic happens'. I really don't know when I might be using it. Can
someone provide examples of how ADL changes the behavior of 'typical' code?
If it were not available, would that absence completely change the way we
use the STL or do other things?
"Hello, world" with argument dependent lookup (ADL):
#include <iostream>
int main()
{
std::cout << "Hello, world!\n";
}
...and without:
#include <iostream>
int main()
{
std::cout.operator<<("Hello, world!\n");
}
Greg
.
|
|
|
| User: "peter koch" |
|
| Title: Re: What would C++ look like without ADL? |
14 Dec 2006 08:29:47 AM |
|
|
Greg skrev:
Steven T. Hatton wrote:
I'll admit, so far in my C++ experience, I've left ADL to the realm
of 'magic happens'. I really don't know when I might be using it. Can
someone provide examples of how ADL changes the behavior of 'typical' code?
If it were not available, would that absence completely change the way we
use the STL or do other things?
"Hello, world" with argument dependent lookup (ADL):
#include <iostream>
int main()
{
std::cout << "Hello, world!\n";
}
...and without:
#include <iostream>
int main()
{
std::cout.operator<<("Hello, world!\n");
}
And complex math with ADL:
int main()
{
std::complex<double> c1,c2,c3;
...
c1 = 2*c2 + c3;
}
And without
int main()
{
std::complex<double> c1,c2,c3;
...
c1 = std::operator+(std::operator*(2,c2),c3);
}
/Peter
.
|
|
|
|
| User: "Steven T. Hatton" |
|
| Title: Re: What would C++ look like without ADL? |
14 Dec 2006 08:48:42 AM |
|
|
Greg wrote:
Steven T. Hatton wrote:
I'll admit, so far in my C++ experience, I've left ADL to the realm
of 'magic happens'. I really don't know when I might be using it. Can
someone provide examples of how ADL changes the behavior of 'typical'
code? If it were not available, would that absence completely change the
way we use the STL or do other things?
"Hello, world" with argument dependent lookup (ADL):
#include <iostream>
int main()
{
std::cout << "Hello, world!\n";
}
...and without:
#include <iostream>
int main()
{
std::cout.operator<<("Hello, world!\n");
}
Greg
There are alternatives.
//bad
using namespace std;
//better but burdensome
using namespace std::operator<<;//I believe that's the correct syntax
There could also be headers with such using declarations in them. For
example they could be part of <iostream>. The argument against doing
something like that is likely to be "we don't want to pollute the global
namespace". As a general rule, I am a strong believer in that principle.
OTOH, I'm not sure that ADL doesn't already introduce hidden pollutants.
I certainly take issue with Danny's conclusions, but he does raise some
interesting issues in this article (rant?):
http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=286&rl=1
--
NOUN:1. Money or property bequeathed to another by will. 2. Something handed
down from an ancestor or a predecessor or from the past: a legacy of
religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/
.
|
|
|
|
|

|
Related Articles |
|
|