I understand that it is a bad practice to have "using namespace std" in general as it pollutes the global namespace. But if I consider a case where I'm writing a command line utility, which has core logic inside an unnamed namespace within the same file.
For example,
namespace myapp{
// Define generic application wide APIs here.
namespace {
using namespace std;
int f(...){
// cli logic
}
}
}
int main(int argc, char** argv){
// parse args
myapp::f(arg1, arg2, ...);
return 0;
}
The namespace myapp
is project specific namespace and many API are enclosed under this namespace. The unnamed namespace will restrict the scope of symbols declared inside it to the current file, so it won't pollute the namespace myapp
. Would it still be considered a bad practice?
Aucun commentaire:
Enregistrer un commentaire