473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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/
Dec 14 '06 #1
7 1554
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

Dec 14 '06 #2

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<doublec1,c2,c3;
...
c1 = 2*c2 + c3;
}

And without
int main()
{
std::complex<doublec1,c2,c3;
...
c1 = std::operator+(std::operator*(2,c2),c3);
}

/Peter

Dec 14 '06 #3
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/conte...eqNum=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/
Dec 14 '06 #4

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?

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.."
--
#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
*/

Dec 14 '06 #5
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/
Dec 14 '06 #6

"Steven T. Hatton" <ch********@germania.supwrote in message
news:co******************************@speakeasy.ne t...
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.

Dec 14 '06 #7

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

Dec 14 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
46
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
8
by: Midnight Java Junkie | last post by:
Dear Colleagues: I feel that the dumbest questions are those that are never asked. I have been given the opportunity to get into .NET. Our organization has a subscription with Microsoft that...
7
by: newbie | last post by:
anyone know is it this source code value:- T = ((Y >> 4) ^ X) & 0x0F0F0F0F; X ^= T; Y ^= (T << 4); T = ((Y ) ^ X) & 0x10101010; X ^= T; Y ^= (T ); X = (LHs << 3) | (LHs << 2)...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Languageâ€, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.