[Boost-bugs] [Boost C++ Libraries] #8011: iterator_range::size() is not SFINAE-friendly

Subject: [Boost-bugs] [Boost C++ Libraries] #8011: iterator_range::size() is not SFINAE-friendly
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-02-08 12:30:25


#8011: iterator_range::size() is not SFINAE-friendly
--------------------------------------------------------+-------------------
 Reporter: Jonathan Wakely <jwakely.boost@…> | Owner: neilgroves
     Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: range
  Version: Boost 1.52.0 | Severity: Problem
 Keywords: |
--------------------------------------------------------+-------------------
 iterator_range<I>::size() is always defined, but fails a static assertion
 if I is not a random access iterator. This means it's not possible to use
 SFINAE To detect whether r.size() is valid.

 By moving the size() member to a new base type like the one below (and
 updating iterator_range to use this->m_Begin and this->m_End everywhere)
 the function will only be present when it can actually be used:

 {{{
         template<class IteratorT, class CategoryT
                  = typename
 std::iterator_traits<IteratorT>::iterator_category>
         class iterator_range_base
         {
         protected:
             template< class Iterator >
             iterator_range_base( Iterator Begin, Iterator End ) :
                 m_Begin(Begin), m_End(End)
             {}

             // begin and end iterators
             IteratorT m_Begin;
             IteratorT m_End;
         };

         template<class IteratorT>
         class iterator_range_base<IteratorT,
 std::random_access_iterator_tag>
         {
         protected:
             template< class Iterator >
             iterator_range_base( Iterator Begin, Iterator End ) :
                 m_Begin(Begin), m_End(End)
             {}

             typedef BOOST_DEDUCED_TYPENAME
                 iterator_difference<IteratorT>::type difference_type;

             // begin and end iterators
             IteratorT m_Begin;
             IteratorT m_End;

         public:
             difference_type
             size() const { return m_End - m_Begin; }
         };
 }}}

 Also, the comment at the top of iterator_range_core.hpp says:

> Defines the \c iterator_class and related functions.

 which should presumably say "iterator_range class" not "iterator_class"

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8011>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:11 UTC