Talk About Network

Google





Programming > C - C++ Learning > Re: Problem wit...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 12 of 15 Topic 4080 of 4400
Post > Topic >>

Re: Problem with compilator DEV C++

by Jerry Coffin <jcoffin@[EMAIL PROTECTED] > Mar 26, 2008 at 07:06 PM

In article <64v536F2db045U1@[EMAIL PROTECTED]
>, r124c4u102@[EMAIL PROTECTED]
 
says...

[ ... ]

> Yes, my point is that it is fundamentally wrong to use either one *in a 
> header file*. Putting
> a using declaration in a header file means that anyone who uses that
file
> must inspect it to see what is there and then *remember* each one that
was
> used.

Not if it's properly do***ented, they don't. They need to know what 
names that header makes visible in any case though -- and the fact that 
some of those names may have originated from namespace std doesn't 
really change anything.

> In a pretty trivial program I would use at least 20 of the names in
> std::.  I do not think I should impose such a burden (remembering my
> personal list) on my fellow programmers just so I can avoid typing a few
> keystrokes.   The advantage of the using thingies that I see, is
avoiding 
> pollution of the source code with noise words. The typing labor can be 
> minimized by the editor or other macro key aids.

Using directives and declarations are not all about saving typing. 
They're often about getting optimal behavior. When I'm writing a 
template, I frequently want to use an implementation in the user's 
namespace if there is one, but otherwise use the implementation in 
namespace std. An obvious example would be a sort routine that swaps 
elements in a collection to sort them. We want it to use the swap 
specific to those elements if there is one, but use std::swap if nothing 
else is available.

For this situation, specifying std::swap gives the wrong behavior. 
Specifying their_namespace::swap doesn't work either, because it might 
not exist. The behavior we want is obtained with a using directive 
followed by an unadorned 'swap', and we leave it to the compiler to find 
the right one.
 
> A widely distributed package that allowed using declarations in its' 
> associated  header file sounds like a Really Bad Idea to me.  I think I
have 
> said pretty much all I want to say on this subject.

Almost any useful header is going to make some set of names visible. The 
number and origins of those names will vary from one header to another. 
The fact that a few of those names may originate from namespace std 
doesn't seem to make a whole lot of difference. What matters is that 1) 
the number is kept reasonable, and 2) that the set of names is fully 
known and do***ented.

A using directive doesn't sup****t either requirement -- the set of names 
(especially in namespace std) is large, unknown, and impossible to 
do***ent. Using declarations fit the requirements quite easily -- it's 
clear exactly what names are being made visible, and do***enting those 
names is fairly trivial.

-- 
    Later,
    Jerry.

The universe is a figment of its own imagination.
 




 15 Posts in Topic:
Problem with compilator DEV C++
"lito" <lit@  2008-03-25 14:58:45 
Re: Problem with compilator DEV C++
"osmium" <r1  2008-03-25 08:01:24 
Re: Problem with compilator DEV C++
"lito" <lit@  2008-03-25 17:51:10 
Re: Problem with compilator DEV C++
"osmium" <r1  2008-03-25 10:29:50 
Re: Problem with compilator DEV C++
Francis Glassborow <fr  2008-03-25 18:57:21 
Re: Problem with compilator DEV C++
Francis Glassborow <fr  2008-03-25 18:55:53 
Re: Problem with compilator DEV C++
"osmium" <r1  2008-03-25 11:14:09 
Re: Problem with compilator DEV C++
Francis Glassborow <fr  2008-03-26 11:15:36 
Re: Problem with compilator DEV C++
Jerry Coffin <jcoffin@  2008-03-26 07:47:57 
Re: Problem with compilator DEV C++
"osmium" <r1  2008-03-26 06:32:07 
Re: Problem with compilator DEV C++
Francis Glassborow <fr  2008-03-26 23:40:18 
Re: Problem with compilator DEV C++
Jerry Coffin <jcoffin@  2008-03-26 19:06:20 
Re: Problem with compilator DEV C++
Francis Glassborow <fr  2008-03-27 11:40:35 
Re: Problem with compilator DEV C++
Jerry Coffin <jcoffin@  2008-03-28 21:04:50 
Re: Problem with compilator DEV C++
Bart van Ingen Schenau &l  2008-03-25 20:28:41 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 12:03:38 PST 2009.