Boost logo

Boost :

From: Dave Harris (brangdon_at_[hidden])
Date: 2005-05-11 12:56:42


In-Reply-To: <00fb01c55599$e9fc23e0$6401a8c0_at_pdimov2>
pdimov_at_[hidden] (Peter Dimov) wrote (abridged):
> I think that defining size( T[N] ) as N or N-1, depending on whether T
> is a character type, will cause problems in generic code and preclude
> the widespread use of the library.

I agree.

If we do support null-terminated character strings, can we support other
kinds of terminators too? (Without undue loss of efficiency.) For example:

     int array[] = { 1, 2, 3, -1 };
     int *pArray = array;
     
     for (int i, terminator_adaptor(pArray,-1))
         cout << i; // Does not write -1.

This can be useful if the size of the array is not visible to for(:).

I use terminators fairly often, usually NULL for pointers, 0 or -1 for
integral types, and "end" for enums. It's not something specific to
characters. In fact, for me the need to enumerate character strings is
rarer than for these other types. Usually strings are either wrapped in
std::string or similar, or else passed to some other routine.

By "Without undue loss of efficiency" I really mean without scanning the
sequence an extra time to find the end. My impression is that
BOOST_FOR_EACH had a fairly general termination mechanism which could cope
with that.

-- Dave Harris, Nottingham, UK.


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