using namespace std;

using namespace std;

Post by Leigh John » Tue, 08 Jun 2010 21:44:30

No it isn't, I use typedefs a lot and never find the need to use using
declarations, in fact extensive use of typedefs makes using declarations
even less necessary.

Very poor argument in favour.

That is just laziness.

See above.


using namespace std;

Post by Leigh John » Tue, 08 Jun 2010 21:46:08

Nonsense argument. std:: prefix makes things more readable, you know
instantly that the name refers to something from the standard library and
not something local, see another thread for a great example.



using namespace std;

Post by Tii » Tue, 08 Jun 2010 21:48:01

"using namespace std;" in header breaks purpose of having std
namespace at first place. All names in std namespace are useful like
global names as result and that will bring some tedious work to do
sooner or later.

Most likely the names in std will clash with the names in boost. All C+
+ developers use things from std and most use some things from boost
too. Most useful things in boost will be both in boost and std with
slight differences sooner or later. Migrating to newer compiler
versions may be therefore painful. Good news are that the issues will
be most likely compile time issues.

What is the purpose of "main include file"? If it is for includung
every other include file then biggest mistake is probably that whole
idiom of main include file. Objects should have limited surroundings
with what they interact. Interacting globally results with global
dependencies and that results with inflexible architecture. Try to
include only the headers that your classes really need.

Yes it was big mistake since namespace std is quite big namespace. You
can make it safer by finding out what you really use in your Actor
application. Replace that "using namespace std;" with "using
std::string; using std::map; using std::list; using std::vector;". If
something else is used massively in lot of places add using
declaration for that too. For the names used more locally add local
using declarations. You may likely leave it as that if you do not want
to refactor to declare everything what you use more locally.

Some people here advocate always fully qualifying. They claim that
they are never sure what "vector" it is unless it is written
"std::vector". I do not believe them. Have they really met so lot of
"foo::vector"s all around the place? When they did, did the difference
really matter and confuse? When it mattered was not the code declaring
"foo::vector" not worth to be thrown away together with its author,
instead of writing std::vector everywhere? Ability to use short form
where it is enough was the whole purpose why authors of standard did
not name it as "std_vector".

I keep using declarations local to implementation since in interface i
prefer typedefing the template instantiations to something more
readable anyway. Also i feel that the #include's and using
declarations at beginning of file give me brief introduction what the
implementation will deal with.

using namespace std;

Post by Stuart Red » Wed, 09 Jun 2010 00:00:08

That's one point where I agree with Leigh. If you want to switch
between namespaces, you should rather use (A) typedefs, if its just
one definition, or (B) a define, if everything should be switched, or
(C) even rename the namespace:

typedef std::cout my_cout;

#define MYSTD std

namespace mystd = std;

If you use the typedef / define, you'll still only say it once.

Of course, the whole discussion is quite superfluous. If "using
namespace std" does your project no harm, there is no reason not to
use it. It's rather bad style, since there are projects where it will
do harm. So as a guideline, one should qualify everything with the
proper namespace.

Let's say no more about it.


using namespace std;

Post by Juha Niemi » Wed, 09 Jun 2010 00:02:26

Great idea, except that std::cout is not a type.

using namespace std;

Post by Leigh John » Wed, 09 Jun 2010 00:39:52

I was thinking more along the lines of:

typedef std::vector<foo> items;
items theItems;
for (items::size_type i = 0; i != theItems.size(); ++i) ...


using std::vector;
vector<foo> theItems;
for (vector<foo>::size_type i = 0; != theItems.size(); ++i) ...

IMO the former is more readable than the later and doesn't need a using
declaration to save on typing which seems to be the primary benefit of using
using declarations (modulo ADL which I try and keep to a minimum).


using namespace std;

Post by Keith H Du » Wed, 09 Jun 2010 01:12:51

It's already been pointed out in the "another thread" that
explicit qualification impedes generic programming. Have you
forgotten about that already?

Of course this doesn't apply to std::cout if we are discussing
only that specific case. (A program littered with cout with or
without qualification is probably a *** program anyhow.)


using namespace std;

Post by Leigh John » Wed, 09 Jun 2010 01:31:00

It only impedes generic programming as far as ADL is concerned but my use of
ADL tends to be mostly limited to operator overloading rather than named
functions. I suspect you over-use ADL and your code looks *** y awful as a


using namespace std;

Post by Paul Bibbi » Wed, 09 Jun 2010 01:45:49

"Leigh Johnston" < XXXX@XXXXX.COM > writes:

Just to get this into context, what would you call an "over-use [of]
ADL" - something like the following?

17:43:14 Paul Bibbings@JIJOU
/cygdrive/d/emacs-23.1/bin $cat adl_over.cpp
// file: adl_over.cpp

namespace one {
class AType { };
void doStuffWithAType(AType) { }

namespace two {
class AType { };
void doStuffWithAType(AType) { }

int main()
using one::AType;
// ...
AType a;

using two::AType;
// ...
AType a;


Paul Bibbings

using namespace std;

Post by Leigh John » Wed, 09 Jun 2010 01:54:33

That is the kind of mess yes I was thinking of yes. Obviously ADL of named
functions can be useful, e.g. to pick up a custom swap() when using another
algorithm such as std::random_shuffle but to be perfectly honest I haven't
found the need to do much of that in practice, I wonder why? Mainly because
std::swap is *usually* sufficient.


using namespace std;

Post by Kai-Uwe Bu » Wed, 09 Jun 2010 01:58:05

eigh Johnston wrote:

Let me quote something you said in another thread:

Why is your level of usage relevant? Are you a god or something which
requires devoted followers? Different people use different features
differently. :)

And why do you feel the need to end with an insult?


Implementing custom versions of standard algorithms like copy can yield some
performance gain. Think of a container class like the old SGI rope. Here
iterators are not all that light, but the container falls into segments and
withing these segments a simple pointer can serve as the iterator. Having a
special loop to deal with the contents of segments makes sense.

Another obvious example where you would want use ADL are math functions like
sin(), log(), ... for high-precision types or objects implementing interval

Such custom implementations of standard algorithms may not be placed in the
standard namespace. Maybe, that is a defect in the language. Nonetheless,
ADL allows generic code to find them properly.

In the end, it very much depends on your code base and the local coding
guidelines. E.g., if they state that names of functions in standard
namespace may not be used elsewhere unless they implement the same
semantics, you can very well rely on ADL. Nonetheless the coding style can
require qualification for std::vector and std::cout.


Kai-Uwe Bux

using namespace std;

Post by Leigh John » Wed, 09 Jun 2010 01:58:16

On a related matter I think the standard requirement that allows user
function templates to be specialized in the ::std namespace but not
overloaded in the ::std namespace is wrong, ill-conceived, a bug, whatever
you want to call it (I can of course be missing something obvious as to why
the requirement exists, I made a separate post but nobody replied).


using namespace std;

Post by Leigh John » Wed, 09 Jun 2010 02:23:11

"Kai-Uwe Bux" < XXXX@XXXXX.COM > wrote in message
news:huj8eu$voe$ XXXX@XXXXX.COM ...

Touche. :)

KHD has insulted me in the past, childish I know but Usenet tends to elevate
the status of people to that of argumentative retards. Seriously there must
be a reason why I haven't found the need to use ADL with named functions
much (if at all). KHD cited swap as an example but is it perfectly
reasonable to mix "std::swap" with the use of algorithms that rely on ADL to
reach a user provided swap in the same codebase. Maybe I incorrectly
assumed that KHD was advocating the use of using declarations even when ADL
was not involved.

I agree with this, see else-thread. I am not advocating against ADL, just
the over-use of using declarations and possible over-use of ADL when it
isn't necessary. It is obvious what "std::equal(a, b, c)" means, it is not
obvious what "equal(a, b, c)" means and using ADL to reach a custom "equal"
is unnecessary if the type of "a" provides a comparison operator.

Yes like I said I have nothing against ADL just using ADL as an excuse for
littering your code with hundreds of unnecessary using declarations I have a
problem with.

I think it is a defect that a user can specialize function templates in the
::std namespace but cannot overload function templates in the ::std



using namespace std;

Post by Leigh John » Wed, 09 Jun 2010 02:25:53

"Leigh Johnston" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...

I should have said "std::equal(a, b)" and "equal(a, b)" of course. :)



using namespace std;

Post by Tii » Wed, 09 Jun 2010 02:39:11

You seem to not know what std::equal does. With 3 arguments it gets 3
input iterators to compare elements in two containers. With 4
arguments it takes additionally a binary predicate.