Changeset 1386 for trunk


Ignore:
Timestamp:
Jul 22, 2008, 10:18:51 PM (13 years ago)
Author:
Peter
Message:

fixes #402 - constness conversion in StrideIterator?

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/iterator_test.cc

    r1382 r1386  
    117117  suite.add(data_iter2 == data_iter5);
    118118  suite.add(data_iter4 == data_iter5);
     119  utility::StrideIterator<std::vector<double>::const_iterator> stride_ci(c_iter);
     120  utility::StrideIterator<std::vector<double>::iterator> stride_i(iter);
     121  suite.add(stride_ci==stride_i);
     122  suite.add(stride_i==stride_ci);
    119123
    120124  utility::MatrixWeighted x_weighted(3,4);
     
    124128  *(x_weighted.begin()+1) = element;
    125129  double element_data = *make_data_iterator(x_weighted.begin());
     130  suite.add(element_data==x_weighted.begin()->data());
    126131
    127132  classifier::MatrixLookup ml(m);
  • trunk/yat/utility/StrideIterator.h

    r1378 r1386  
    2828#include "iterator_traits.h"
    2929#include "yat_assert.h"
     30
     31#include <boost/iterator/iterator_adaptor.hpp>
    3032
    3133#include <iterator>
     
    126128   
    127129    /**
    128        Conversion from mutable iterator to const iterator. Only works
    129        if underlying iterator is a pointer.
    130      */
    131     // Peter, this is ugly hack to provide iterator to const_iterator
    132     // for our gsl_iterators - solution? use Boost:iterator_adaptor
    133     operator StrideIterator<const value_type*>()
    134     { return StrideIterator<const value_type*>(base(), stride_); }
     130       \brief Conversion constructor.
     131
     132       Create a StrideIterator<Iter> from a StrideIterator<I2>. Possible
     133       if I2 is convertible to a Iter. Constructor allows implicit
     134       conversions such as iterator to const_iterator.
     135     */
     136    template<typename I2>
     137    StrideIterator(StrideIterator<I2> other,
     138                   typename boost::enable_if_convertible<I2, Iter>::type* = 0 )
     139      : iterator_(other.base()), stride_(other.stride()) {}
    135140
    136141    /**
Note: See TracChangeset for help on using the changeset viewer.