comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <no.spam@no.spam.com>
Subject: Re: Negative float problem
Date: Fri, 28 Oct 2005 10:34:03 +0200
Date: 2005-10-28T10:34:03+02:00	[thread overview]
Message-ID: <djsnpq$1oa$1@sunnews.cern.ch> (raw)
In-Reply-To: <wccoe5bc67l.fsf@shell01.TheWorld.com>

Robert A Duff wrote:

>>What about Argument-Dependent Lookup (C++ has it)?
> 
> What's ADL?  I'm reasonably fluent in C++, but I don't know that term.

Which means that the feature is well designed. ;-)

> Also, can you give an example?

Sure.

#include <iostream>

int main()
{
     std::cout << "Hello!\n";
}

Above, iostream was #included, but there is no "using namespace std;" in 
the code. The result is that you have to qualify cout (so that you have 
to write std::cout), but at the same time you don't have to qualify the 
operator<<, even though it is also defined in namespace std and is 
otherwise *not* directly visible.

Basically, the function (and operator) names are *additionally* looked 
up in those namespaces where their parameters are declared. This is 
usefull for operators like above (and certainly applies to the original 
Ada problem in this thread), but can also help with normal functions.

Without this feature, you would have to write:

std::operator<<(std::cout, "Hello\n");

which obviously is not what is wanted.

> It's not particularly an issue of how smart the compiler is.
> Certainly, if the rules were as you suggest, compilers could
> implement them just as easily as the current rules.  In fact,
> the rules you suggest are equivalent to always having a use clause,
> if I understand what you mean.

No, it is not like this. It is an extension of the lookup mechanism, not 
the implicit use clause.

> As to "why not other operations as well?" -- I think it's reasonable to
> require a use clause to get them.

If you allow ADL for operators, it is reasonable to allow it for all 
functions and procedures. There is no point in complicating rules and 
creating further special cases.

> And in many cases, it's useful to
> avoid the use clause, and use Package_Name.Procedure_Name notation,
> because that allows the reader to understand where Procedure_Name
> comes from.

Absolutely. ADL is *not* an implicit use clause and is used in those 
places, where it significantly helps rather than obscuring the code.
And nobody prevents you from writing fully qualified names even when it 
is not necessary, but you find it to improve the readability of the code.

> Note that in C++, you will generally be referring to an object name as a
> prefix, which somewhat mimics the Ada "Package_Name." idea.

Note that in C++ there are also free functions, which use objects as 
their arguments (in fact, the operator<< for ostream falls into this 
category). This is exactly where ADL is supposed to help (and it cannot 
be used anywhere else for that matter, so it does not kick in where it's 
not wanted).

>>I'm really surprised that the code posted at the beginning of this
>>thread does not compile.
> 
> Many people are.

So - why not having ADL in Ada? :)


-- 
Maciej Sobczak : http://www.msobczak.com/
Programming    : http://www.msobczak.com/prog/



  reply	other threads:[~2005-10-28  8:34 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-26 18:32 Negative float problem Luke
2005-10-26 19:05 ` Samuel Tardieu
2005-10-26 20:42 ` Robert A Duff
2005-10-27  8:05   ` Robert I. Eachus
2005-10-27 14:48     ` Robert A Duff
2005-10-27 15:07       ` Maciej Sobczak
2005-10-27 15:47         ` Robert A Duff
2005-10-28  8:34           ` Maciej Sobczak [this message]
2005-10-29 23:39             ` Brian May
2005-10-30  9:11             ` Dmitry A. Kazakov
2005-10-31  9:46               ` Maciej Sobczak
2005-10-31 14:20                 ` Dmitry A. Kazakov
2005-11-01 11:06                   ` Maciej Sobczak
2005-11-01 14:06                     ` Robert A Duff
2005-11-01 14:46                       ` Martin Dowie
2005-11-01 16:04                         ` Hyman Rosen
2005-11-01 17:19                           ` Martin Dowie
2005-11-02  0:13                         ` Robert A Duff
2005-11-02  6:59                           ` Martin Dowie
2005-11-02 13:24                             ` Robert A Duff
2005-11-02 15:22                               ` Martin Dowie
2005-11-01 15:12                       ` Maciej Sobczak
2005-11-02  0:28                         ` Robert A Duff
2005-11-02  4:16                           ` Steve Whalen
2005-11-14  7:26                           ` Dave Thompson
2005-11-20  0:19                             ` Robert A Duff
2005-11-20 11:07                               ` Dmitry A. Kazakov
2005-11-01 14:27                     ` Dmitry A. Kazakov
2005-11-01 15:19                       ` Maciej Sobczak
2005-11-01 19:44                         ` Dmitry A. Kazakov
2005-11-02  9:04                           ` Maciej Sobczak
2005-11-02 11:17                             ` Dmitry A. Kazakov
2005-11-02 13:03                               ` Maciej Sobczak
2005-11-02 14:20                                 ` Jean-Pierre Rosen
2005-11-02 20:15                                   ` Jeffrey R. Carter
2005-11-03 13:06                                     ` Jean-Pierre Rosen
2005-11-03 18:32                                       ` Jeffrey R. Carter
2005-11-03  9:51                                   ` Maciej Sobczak
2005-11-03 13:20                                     ` Jean-Pierre Rosen
2005-11-03 15:02                                       ` Maciej Sobczak
2005-11-03 18:55                                         ` Frank J. Lhota
2005-11-04  9:32                                           ` Maciej Sobczak
2005-11-03 20:59                                     ` Simon Wright
2005-11-02 13:32                               ` Robert A Duff
2005-11-02 14:44                                 ` Dmitry A. Kazakov
2005-11-02 13:47                               ` Dmitry A. Kazakov
2005-10-27 18:33       ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox