Re: std::transform too strict in debug mode?



On Mar 4, 7:37 pm, MathGis <mtahilfer...@xxxxxxxxxxx> wrote:
Hi,

the following code gives (when compiled with VC++2005 in Debug mode) a
runtime error in the std::transform function:

#include <functional>
#include <algorithm>

int main(int argc, char** argv)
{
        const int* first = 0;
        const int* last  = 0;
        int* result = 0;
        std::copy(first, last, result); // OK
        std::transform(first, last, result, std::negate<int>()); // BOOM
                return 0;

}

I think this code is legal. Is this implementation of std::transform
too strict in checking for 'invalid' null pointers? Note that the
equivalent check in std::copy is as follows:
        if (_First != _Last)
                _DEBUG_POINTER(_Dest);
but in std::transform the if is missing.

I agree that the _DEBUG_POINTER tests for _Dest and _Func
should be protected the same way.

Thanks for pointing out the problem.

P.J. Plauger
Dinkumware, Ltd.
http://www/dinkumware.com
.



Relevant Pages