Boost logo

Boost :

From: Dean Sturtevant (deansturtevant_at_[hidden])
Date: 2001-01-23 15:24:09

I have objections.
Much of debug functionality would be implemented by using asserts.
These asserts should go in the code one uses even in non-debug
versions. Thus I don't see much use for a separate header file for
the debug code. Also, this means that one cannot have something like:

namespace boost
template <class Type>
class Array
     Type& operator[](unsigned index){
        assert(index < size());
        return m_elements[index];

because that would violate the ODR (boost::Array<Type>::operator[]()
would have a different definition for NDEBUG).

Instead one would need to say:
#ifndef NDEBUG
#define BOOST_NAMESPACE boost_debug
namespace boost_debug {}
namespace boost = boost_debug;
#define BOOST_NAMESPACE boost


--- In boost_at_[hidden], Gregory Seidman <gseidman_at_a...> wrote:
> Okay, try this on for size. We have two namespaces: boost_debug and
> boost_optimized (or whatever... bear with me). Each boost header
> something like this:
> #ifndef NDEBUG
> //the code in this file is contained in namespace boost_debug;
> #include <boost/thisfunctionality_debug.hpp>
> #else
> //the code in this file is contained in namespace boost_optimized
> #include <boost/thisfunctionality_optimized.hpp>
> #endif
> namespace boost {
> #ifndef NDEBUG
> using namespace boost_debug;
> #else
> using namespace boost_optimized;
> #endif
> }
> Now, the debug stuff is in a separate namespace from the ordinary or
> optimized version, so linking between debugging and non-debugging
> will fail outright. Nonetheless, the programmer simply uses boost::
> using namespace boost) to access whichever version (which will be
> into the boost namespace), but the version is chosen at compile-
time with
> (or without) -DNDEBUG. Note that the includes in the middle could
just be
> the appropriate definitions in the appropriate namespace; I showed
it as
> includes for simplicity and readability.
> We preserve ODR while preserving ease of use. Any objections?
> --Greg

Boost list run by bdawes at, gregod at, cpdaniel at, john at