extending 'import' using 'with'
Dennis Ritchie via Digitalmars-d
digitalmars-d at puremagic.com
Thu Apr 2 02:52:45 PDT 2015
On Wednesday, 1 April 2015 at 13:35:22 UTC, ketmar wrote:
> people with Java/C/C++/etc. background tend to forget about the
> power of
> metaprogramming: they have no such tool at hand, so they don't
> even think
> about it.
C++ with boost:
-----
#include <iostream>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
namespace a { namespace b {
namespace x {
int test1 = 1;
}
namespace y {
int test2 = 2;
}
namespace z {
int test3 = 3;
}
}
}
#define USE_NAMESPACES_IMPL( r, root, name ) \
using namespace root :: name;
#define USE_NAMESPACES( root, names ) \
BOOST_PP_SEQ_FOR_EACH( USE_NAMESPACES_IMPL, root, names )
USE_NAMESPACES( a::b, (x)(y)(z) )
int main() {
std::cout << test1 << '\n'; // 1
std::cout << test2 << '\n'; // 2
std::cout << test3 << '\n'; // 3
return 0;
}
-----
http://ideone.com/LncucP
More information about the Digitalmars-d
mailing list