In C++11 I can choose whether I want to use the types defined in with or without the namespace std::
At least my compiler (g++ 4.7) accepts both variants.
My question is: What is the recommended way to use the typedefs from cstdint. With or without the namespace? What are the advantages or disadvantages? Or is it only a matter of style?
so variant a):
#include <cstdint>
std::uint8_t n = 21;
resp:
#include <cstdint>
using std::uint8_t;
uint8_t n = 21;
or variant b):
#include <cstdint>
uint8_t n = 21;
Prefer names declared in the
stdnamespace. The reason is given in §17.6.1.3/4 (ISO/IEC 14882:2011(E), C++11):If you use the names from the
<cname>headers withoutstd, your program is relying on unspecified requirements.This was different in C++03 and earlier where names were only supposed to appear in the
stdnamespace. However, the reality was that many implementations were simply injecting the contents of the C standard library headers<name.h>intostdand so this was accommodated for in C++11. The corresponding section (§17.4.1.2/4) from the C++03 standard says:Further to this, qualifying names with
std::helps to avoid collisions – you know exactly what you’re getting if you fully qualify it. If you’re really going to dousing namespace stdorusing std::something, at least do it in as minimal a scope as you can.