vendredi 29 janvier 2016

Are name spaces required for free functions in the STL?

I'm playing around with my coding style. I used to explicitly prefix every library call with std:: but I'm switching over to using declarations like this:

using std::count;
using std::vector;

One thing I've noticed over the past few days is that sometimes if I forget a using declaration -- using std::vector; is a good example -- I get reams of compiler errors. However, if I neglect to namespace delcare an algorithm such as using std::count; my code compiles just fine.

Does this have to do with the difference with classes and free functions? On all the reference sites, both count(first, last, value) and vector are prefixed with std:: so I would expect them to behave the same.

Or does it have to do with other functions in the global namespace? I notice std::max also seems to require a namespace declaration, perhaps it defined in a default-included Apple/glibc/LLVM file and thus there is a conflict if I used it sans namespace declaration?

I am using Apple LLVM 7.0.2. on El Capitan.

Aucun commentaire:

Enregistrer un commentaire