fork download
  1. #include <iostream>
  2.  
  3. #include <boost/preprocessor/cat.hpp>
  4. #include <boost/preprocessor/seq/for_each.hpp>
  5.  
  6. namespace a { namespace b {
  7. namespace x {
  8. int test1 = 1;
  9. }
  10. namespace y {
  11. int test2 = 2;
  12. }
  13. namespace z {
  14. int test3 = 3;
  15. }
  16. }
  17. }
  18.  
  19. #define USE_NAMESPACES_IMPL( r, root, name ) \
  20.   using namespace root :: name;
  21.  
  22. #define USE_NAMESPACES( root, names ) \
  23.   BOOST_PP_SEQ_FOR_EACH( USE_NAMESPACES_IMPL, root, names )
  24.  
  25. USE_NAMESPACES( a::b, (x)(y)(z) )
  26.  
  27. int main() {
  28.  
  29. std::cout << test1 << '\n';
  30. std::cout << test2 << '\n';
  31. std::cout << test3 << '\n';
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
1
2
3