|
Boost : |
From: Andy (atompkins_at_[hidden])
Date: 2007-03-20 16:22:51
me22 <me22.ca_at_[hidden]> wrote in
news:fa28b9250703201126y574108d7r1c6f5f9d4584745a_at_[hidden]:
> 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.
Good point! Thanks.
>
> 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
>
I will add this to my to do list.
Andy.
< snip >
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk