Opened 7 years ago
Last modified 7 years ago
#11348 new Bugs
Problem constructing boost::iterator_range objects from arrays
Reported by: | Owned by: | Neil Groves | |
---|---|---|---|
Milestone: | To Be Determined | Component: | range |
Version: | Boost 1.58.0 | Severity: | Regression |
Keywords: | Cc: |
Description
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:
#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
+1