c++ - Is a using-directive in a detail namespace problematic? -


consider library header:

#include<vector> #include<algorithm> #include<iostream>  namespace lib {   namespace detail {     using namespace std;      template<class t>     void sort_impl(istream &in,ostream &out) {       vector<t> v;       {         int n;         in >> n;         v.resize(n);       }       for(auto &i : v) cin >> i;        sort(v.begin(),v.end());       for(auto : v) out << << endl;     }   }    inline void sort_std() {     detail::sort_impl<int>(std::cin,std::cout);   } } 

does detail namespace isolate clients of library (and rest of library's implementation) using-directive in example? i'm not interested in discussion @ why "using namespace std" considered bad practice?, though of arguments apply "well contained" using-directives.

note there 2 existing questions concerning same situation using-declarations:

this combined either of them, editing severe.

you pollute own detail namesapce, not lib or global namespaces. assuming responsible adult using library, won't have unintentional name collisions:

#include <vector>  namespace lib {   namespace detail {     using namespace std;   } }  using namespace lib;  int main() {     vector<int> v; // error, vector not declared in scope } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -