Changeset 3393


Ignore:
Timestamp:
Mar 17, 2015, 4:38:36 AM (5 years ago)
Author:
Peter
Message:

refs #803

The std::random_access_iterator promises that iterator provides random
traversal and that reference_type is an lvalue (i.e. not proxy). If
reference_type is a proxy, it is therefore incorrect to tag the
iterator with std::random_access_iterator. To reflect that we do the
following two changes:

1) Container2DIterator now carries tag
boost::random_access_traversal_tag rather than
std::random_access_iterator. This means that in std:: speak a
Container2DIterator is a random access iterator, if reference is an
lvalue and an input iterator otherwise.

2) The BASE of StrideIterator? is no longer required to be a random
access iterator, instead we require random access traversal.
Therefore, StrideIterator? now uses the default tag rather than
std::iterator_traits<BASE>::iterator_category. This means that the
traversal tag is boost::random_access_traversal_tag (as BASE is
required to provide random access traversal), and in std:: speak the
same rule applies as for Container2DIterator.

3) The concept check for Container2D now requires that iterators
::const_iterator, ::const_row_iterator, ::const_column_iterator are
readable iterator (the random access requirement is removed).

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEWS

    r3364 r3393  
    88  - AveragerWeighted::n(void) now return 0, when object is empty (ticket #802)
    99  - added support for htslib (see ticket #794)
     10  - Container2DIterator is now tagged with
     11    boost::random_access_traversal_tag (see ticket #803, r3393)
     12  - StrideIterator is now tagged with use_default (see ticket #803, r3393)
    1013
    1114  A complete list of closed tickets can be found here [[br]]
  • trunk/test/iterator.cc

    r3379 r3393  
    499499    x *= 2; // avoid compiler warning
    500500
    501     // ticket #623
     501    // ticket #623 is about iterator below did not pass boost concept
     502    // check as a random access iterator.
    502503    typedef utility::Container2DIterator<const classifier::KernelLookup,
    503504      double, const double> c2dIter;
    504     BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<c2dIter>));
     505    // The workaround in #623 is dirty as it circumvent the fact that
     506    // random access iterators are required to return lvalue from
     507    // operator*. This is further explained in //
     508    // http://www.boost.org/doc/libs/1_57_0/libs/iterator/doc/index.html
     509    // and ticket #803. So here we replace the check for C++98 style
     510    // random access iterator with boost style readable and
     511    // random_access_traversal.
     512    //BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<c2dIter>));
     513    BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<c2dIter>));
     514    BOOST_CONCEPT_ASSERT((boost_concepts::RandomAccessTraversal<c2dIter>));
    505515
    506516    typedef StrideIterator<c2dIter> StrideIter;
    507     StrideIter::iterator_category x623;
    508     std::random_access_iterator_tag y623(x623);
    509     BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<StrideIter>));
     517    BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<StrideIter>));
     518    BOOST_CONCEPT_ASSERT((boost_concepts::RandomAccessTraversal<StrideIter>));
     519
     520    // the minimal requirement for BASE is that BASE is random access traversal
     521    typedef int value_type;
     522    typedef boost::iterator_archetypes::readable_iterator_t access_type;
     523    typedef boost::random_access_traversal_tag traversal;
     524    typedef boost::iterator_archetype<value_type, access_type, traversal> Base;
     525    StrideIterator<Base> si;
    510526  }
    511527}
  • trunk/yat/utility/Container2DIterator.h

    r3295 r3393  
    6363    Container2DIterator<Container, value, reference>
    6464    , value
    65     , std::random_access_iterator_tag
     65    , boost::random_access_traversal_tag
    6666    , reference>
    6767  {
  • trunk/yat/utility/StrideIterator.h

    r2992 r3393  
    2626#include <boost/concept_check.hpp>
    2727#include <boost/iterator/iterator_adaptor.hpp>
     28#include <boost/iterator/iterator_concepts.hpp>
    2829
    2930namespace theplu {
     
    4142     by combining StrideIterator with a reverse_iterator (from
    4243     e.g. std or boost).
     44
     45     Type Requirements:
     46     - \c RandomAccessIterator must be a \readable_iterator
     47     - \c RandomAccessIterator must be a \random_access_traversal_iterator
    4348  */
    4449  template<typename RandomAccessIterator>
    4550  class StrideIterator
    4651    : public boost::iterator_adaptor<StrideIterator<RandomAccessIterator>
    47                                      , RandomAccessIterator
    48                                      , boost::use_default
    49       , typename std::iterator_traits<RandomAccessIterator>::iterator_category>
     52                                     , RandomAccessIterator>
    5053  {
    5154    typedef boost::iterator_adaptor<StrideIterator<RandomAccessIterator>,
    52                                     RandomAccessIterator,
    53                                     boost::use_default,
    54       typename std::iterator_traits<RandomAccessIterator>::iterator_category>
     55                                    RandomAccessIterator>
    5556    super_t;
    5657
     
    6768      : StrideIterator::iterator_adaptor_(), stride_(stride)
    6869    {
    69       BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<RandomAccessIterator>));
     70      using boost_concepts::RandomAccessTraversal;
     71      using boost_concepts::ReadableIterator;
     72      BOOST_CONCEPT_ASSERT((ReadableIterator<RandomAccessIterator>));
     73      BOOST_CONCEPT_ASSERT((RandomAccessTraversal<RandomAccessIterator>));
    7074    }
    7175
  • trunk/yat/utility/concept_check.h

    r3114 r3393  
    3030#include <boost/concept_archetype.hpp>
    3131#include <boost/concept_check.hpp>
     32#include <boost/iterator/iterator_concepts.hpp>
    3233
    3334namespace theplu {
     
    8990      n = t_.columns();
    9091      some_func(n);
    91       BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_iterator>));
    92       BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_row_iterator>));
    93       BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_column_iterator>));
     92      using boost_concepts::ReadableIterator;
     93      BOOST_CONCEPT_ASSERT((ReadableIterator<const_iterator>));
     94      BOOST_CONCEPT_ASSERT((ReadableIterator<const_row_iterator>));
     95      BOOST_CONCEPT_ASSERT((ReadableIterator<const_column_iterator>));
    9496    }
    9597
Note: See TracChangeset for help on using the changeset viewer.