Boost logo

Boost :

From: Pavol Droba (droba_at_[hidden])
Date: 2007-05-16 05:00:43


Hi,

JD wrote:
> Hi Pavol,
>
> Pavol Droba wrote:
>> Just one quick question. Why do you require size specification? Range
>> have the facilities to determine the size. Why not use it?
>
> I don't know, I though it would be bad practice, for some reason...
> Anyway, it's fixed now, check out the new code uploaded here :
> http://minilien.com/?BXMB4vXUdS
>

Function signature looks fine now, but if you want to be
range-compliant, there are few issues in your implementation.

1.
instead of
        std::size_t Arg1Size = Arg1End - Arg1It;
use
        boost::range_size<Arg1>::type Arg1Size = size(Arg1);

The reason for this is that not all ranges have to use std::size_t and
not all ranges have random access iterators, therefors the simple
substraction of Arg1End - Arg1It might not work.

Better way would be to use std::distance, but the best way is to use
"size" since it can take advantage of internal range representation.

2.
I don't like the usage of plane C-Arrays. Even if you wanna use them,
you should wrap the pointers to something like boost::scoped_array.
Currently your code does not provide even the basic exeption quarantie
(you will unconditionaly leak memory if an exception is thrown) and
that's bad for this kind of algorithm.

Regards,
Pavol.


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