namespaces

I want to know if there are more namespaces like std and it'll be pretty helpful if you could share some more info about namespace.
thnx
Please do some research before posting.
http://en.cppreference.com/w/cpp/language/namespace
What was helpful for me knowing about namespaces was that the std contains tremendous features. By using:

1
2
3
4
#include <iostream>
#include <string>
#include <vector>
using namespace std;


you unlock it all. That might not be what you want to do. Maybe it's only necessary to unlock the features that are used in the code.

using the following:
1
2
3
4
5
6
7
8
9
#include <iostream>
#include <string>
#include <vector>

using std::cout;
using std::cin;
using std::ostream;
using std::string;
using std::vector;


is enough for an application that uses vectors, strings and some input/output.
Caruso - you've just stirred a hornet's nest on this forum
Oh did I? I wasn't aware of that. Sorry about that.
> Oh did I? I wasn't aware of that. Sorry about that.

If you have questions about C++, feel free to ask them here, no matter what they are; don't let people intimidate you into silence.

The particular question that you raised is a valid one, it can be discussed in a sane and sober manner. There is no controversy except where bigoted idiots, who try to demand the the whole world must bow to their stylistic whims and fancies in how code is to be written, are involved.

While certain rules are universally accepted (for example: do not using declarations and directives in header files), there are two valid points of view:

One which says that using declarations and directives are perfectly acceptable in implementation files, especially if it is local to a scope; if you perceive that it aids readability, use it.

In short: You can and should use namespace using declarations and directives liberally in your implementation files after #include directives and feel good about it. Despite repeated assertions to the contrary, namespace using declarations and directives are not evil and they do not defeat the purpose of namespaces. Rather, they are what make namespaces usable.
...
But using declarations and directives are for your coding convenience, and you shouldn't use them in a way that affects someone else's code. In particular, don't write them anywhere they could be followed by someone else's code: Specifically, don't write them in header files (which are meant to be included in an unbounded number of implementation files, and you shouldn't mess with the meaning of that other code) or before an #include (you really don't want to mess with the meaning of code in someone else's header).

- Sutter and Alexandrescu in 'C++ Coding Standards: 101 Rules, Guidelines, and Best Practices'


SF.6: Use using namespace directives ... for foundation libraries (such as std) ...

using namespace can lead to name clashes, so it should be used sparingly. However, it is not always possible to qualify every name from a namespace in user code (e.g., during transition) and sometimes a namespace is so fundamental and prevalent in a code base, that consistent qualification would be verbose and distracting.

CoreGuideLines https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rs-using


The other, which says that using explicit namespace prefixes, even in implementation files, makes the code clearer, and more portable.

In implementation files (e.g. .cpp files), the rule is more of a stylistic rule, but is still important. Basically, using explicit namespace prefixes makes the code clearer, because it is immediately obvious what facilities are being used and where they are coming from. And more portable, because namespace clashes cannot occur between LLVM code and other namespaces. The portability rule is important because different standard library implementations expose different symbols (potentially ones they shouldn't), and future revisions to the C++ standard will add more symbols to the std namespace. As such, we never use 'using namespace std;' in LLVM.
- LLVM Coding Standardsre portable.


Think about it, and then as a general practise, follow what appeals to you more.
Sorry about that

no, you shouldn't be. that's what this forum is all about. in fact if you can get your hands on that thread it will be most illuminating. good luck!
There was a slightly more in-depth discussion about the topic more or less recently (it's been a few weeks)
I think it's this thread
http://www.cplusplus.com/forum/beginner/212153/
A so don't use namespaces in header files. It does make sense. I just did not think of that myself. Thank you.
Topic archived. No new replies allowed.