[Boost-bugs] [Boost C++ Libraries] #11348: Problem constructing boost::iterator_range objects from arrays

Subject: [Boost-bugs] [Boost C++ Libraries] #11348: Problem constructing boost::iterator_range objects from arrays
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-05-26 20:02:12


#11348: Problem constructing boost::iterator_range objects from arrays
------------------------------+------------------------
 Reporter: graham@… | Owner: neilgroves
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: range
  Version: Boost 1.58.0 | Severity: Regression
 Keywords: |
------------------------------+------------------------
 I'm migrating to boost 1.58.0 from an older version and have found that
 I'm no longer able to construct a boost::iterator_range directly from an
 array. The following code snippet demonstrates the problem:

 {{{
 #!cpp
 #include <boost/range/iterator_range.hpp>
 int main()
 {
     int arr[] = { 1, 2 };
     boost::iterator_range<int *> x = arr;
 }
 }}}

 Using gcc 4.9.2 on Linux with Boost 1.58.0, the following error is
 produced:

 {{{
 foo.cpp: In function 'int main()':
 foo.cpp:5:38: error: conversion from 'int [2]' to non-scalar type
 'boost::iterator_range<int*>' requested
      boost::iterator_range<int *> x = arr;
                                       ^
 }}}

 The code compiles fine with older versions of Boost (e.g. 1.53.0). It
 appears that the problem was introduced with this change:
 https://github.com/boostorg/range/commit/7d13f63d5d1324abf519b67f59e1814b2cbe5d55
 although I have not manually verified this.

 From my brief reading of the change introduced here, it seems to deem a
 type that is convertible to the base iterator type to not be a compatible
 range. In the example above, int[2] is convertible to int *, hence the
 constructor is excluded from consideration.

 It appears I can work around the problem by calling
 boost::make_iterator_range, but I would have to change quite a lot of code
 to use this workaround. Hence I wanted to verify that the previous
 behaviour was expected, and find out if a fix is possible.

 I'm happy to help work on a patch, for example perhaps the
 is_compatible_range check can be tightened to explicitly check for the
 array case.

 Thanks,

 Graham

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/11348>
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:18 UTC