Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#8338 closed Bugs (fixed)

Iterator range does not work with pointer to array as iterator

Reported by: Nathan Ridge Owned by: Neil Groves
Milestone: To Be Determined Component: range
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

The following code:

#include <boost/range/iterator_range.hpp>

template <typename T>
boost::iterator_range<const T*> one_element_range(const T& t)
{
    return boost::iterator_range<const T*>(&t, &t + 1);
}

int main()
{
    one_element_range("foo");
}

fails to compile with the following error:

In file included from test.cpp:1:
In file included from boost/range/iterator_range.hpp:13:
boost/range/iterator_range_core.hpp:349:12: error: function cannot return array type 'abstract_value_type' (aka 'char [4]')
           abstract_value_type operator()( difference_type at ) const
           ^
test2.cpp:11:5: note: in instantiation of template class 'boost::iterator_range<char const (*)[4]>' requested here
    one_element_range("foo");
    ^

I think this use case (pointer to an array as an iterator) should be supported.

Attachments (1)

iterator-range-pointer-to-array.patch (1.6 KB ) - added by Nathan Ridge 10 years ago.
patch + test

Download all attachments as: .zip

Change History (5)

by Nathan Ridge, 10 years ago

patch + test

comment:1 by Nathan Ridge, 10 years ago

(In [83596]) [range] allow iterator_range to be instantiated with a pointer to an array as the iterator type (refs #8338)

comment:2 by Nathan Ridge, 10 years ago

Fixed in trunk.

comment:3 by Nathan Ridge, 9 years ago

Resolution: fixed
Status: newclosed

(In [84823]) [range] Merge Boost.Range bug fixes to release branch (fixes #6944; fixes #7407; fixes #7408; fixes #7731; fixes #7827; fixes #8338; fixes #8453).

comment:4 by Nathan Ridge, 9 years ago

Fixed for 1.54.

Note: See TracTickets for help on using tickets.