|
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;
#else
#define BOOST_NAMESPACE boost
#endif
namespace BOOST_NAMESPACE
{
...
}
--- 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
looks
> something like this:
>
> #ifndef BOOST_THISFUNCTIONALITY_HPP
> #define BOOST_THISFUNCTIONALITY_HPP
>
> #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
> }
>
> #endif //BOOST_THISFUNCTIONALITY_HPP
>
> Now, the debug stuff is in a separate namespace from the ordinary or
> optimized version, so linking between debugging and non-debugging
objects
> will fail outright. Nonetheless, the programmer simply uses boost::
(or
> using namespace boost) to access whichever version (which will be
drawn
> 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 acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk