Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-06-27 21:36:57


Beman Dawes wrote:
> That, coupled with the tendency for each major library to have
> "exception.hpp", etc., increases the chance of name clashes.
> Thus give serious consideration to "boost/numerics/ublas/filename.hpp"
> and namespace boost::numeric::ublas.
>
> Then, to ease use:
>
> namespace ub = boost::numeric::ublas;
>
> or whatever. It helps to always use the same alias.

There is even more to it: if your global scope namespace alias happened to
match the name of any other entity in global scope of the program, then
you're entered the realms of undefined behavior, e.g. this

[file1.cpp]
#include "boost/numerics/ublas/filename.hpp"

namespace ub = boost::numeric::ublas;
//..

[file2.cpp]

namespace ub = some_other_long_namespace_name;

// or struct ub { /* ... */ };
// or void ub();
// etc.

invokes an undefined behavior if both translation units are part of the same
program.

FWIW, MPL provides a special header, "boost/mpl/alias.hpp", that user can
include to get an equivalent of

    namespace {
    namespace mpl = boost::mpl;
    }

definition, e.g.

    #include "boost/mpl/list.hpp" // for boost::mpl::list
    #include "boost/mpl/alias.hpp" // namespace alias

    // now we can use 'mpl::' instead of longish 'boost::mpl::'
    typedef mpl::list<char,short,int> types;

/Aleksey


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