Boost logo

Boost :

Subject: [boost] [utility]proposal for a small utility of namespace
From: law chrono (chronolaw_at_[hidden])
Date: 2013-02-25 01:11:05


I like c++ and boost£¬but write namespace is a boring work for brace-matching.

So I write a small util with boost.preprocessor, like below:

#ifndef BOOST_NAMESPACE_UTILITY_HPP_
#define BOOST_NAMESPACE_UTILITY_HPP_

#include <boost/preprocessor/seq/for_each.hpp>

#define _PP_NS_BEGIN_FUNC(r,data,elem) namespace elem {
#define _PP_NS_END_FUNC(r,data,elem) }

#define BOOST_BEGIN_NAMESPACE(SEQ) \
        BOOST_PP_SEQ_FOR_EACH(_PP_NS_BEGIN_FUNC, ~, SEQ)

#define BOOST_ END_ NAMESPACE (SEQ) \
        BOOST_PP_SEQ_FOR_EACH(_PP_NS_END_FUNC, ~, SEQ)

#endif //BOOST_NAMESPACE_UTILITY_HPP_

Then the code can be more clear and easy-reading:

BOOST_BEGIN_NAMESPACE((boost)(asio)(ip))
//namespace boost{namespace asio{namespace ip{

... //to something

BOOST_END_NAMESPACE((boost)(asio)(ip)) //}}}

c++11 inline namespace also can work:

inline BOOST_BEGIN_NAMESPACE((detail))
... //to something
BOOST_END_NAMESPACE((detail))

I wander to know whether this util could be a part of boost.

Thanks a lot.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk