Boost logo

Boost :

From: me22 (me22.ca_at_[hidden])
Date: 2007-03-20 14:26:46


Small thing I noticed in the implementation of
    template <typename ByteInputIterator>
    guid(ByteInputIterator first, ByteInputIterator last)
    {
        if (std::distance(first, last) != 16) {
            boost::throw_exception(std::invalid_argument("invalid
input iterator pair, must span 16 bytes"));
        }
        data_type::iterator i_data = data_.begin();
        while (first != last) {
            *i_data++ = numeric_cast<uint8_t>(*first++);
        }
    }
You suggest that you want input iterators, and the invalid_argument
message mentions input iterators, but your code doesn't work with
input iterators as it traverses the range twice.

It should probably ask for forward iterators or use something like

    template <typename ByteInputIterator>
    guid(ByteInputIterator first, ByteInputIterator last)
    {
        data_type::iterator i_data = data_.begin();
        int i = 0;
        for (; i < 16 && first != last; ++i) {
            *i_data++ = numeric_cast<uint8_t>(*first++);
        }
        if ( i != 16 ) {
            boost::throw_exception(std::invalid_argument("invalid
input iterator pair, must span at least 16 bytes"));
        }
    }

~ Scott McMurray

On 3/20/07, Andy <atompkins_at_[hidden]> wrote:
> I have uploaded a new version to the Boost Vault.
>
> It is now a header only library.
>
> It can be downloaded (guid_v6.zip) at:
> http://www.boost-consulting.com/vault/
>
> or direct download link:
> http://www.boost-consulting.com/vault/index.php?
> action=downloadfile&filename=guid_v6.zip&directory=&
>
> Andy Tompkins
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>


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