Opened 9 years ago
Closed 9 years ago
#9072 closed Patches (fixed)
`iterator_range` does not accept iterators having "reference to function type" as `reference` nested type
| Reported by: | Michel Morin | Owned by: | Neil Groves |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | range |
| Version: | Boost Development Trunk | Severity: | Problem |
| Keywords: | Cc: |
Description
This is a very minor thing.
This code works:
#include <iostream>
#include <boost/iterator/transform_iterator.hpp>
void zero() { std::cout << "zero" << std::endl; }
void non_zero() { std::cout << "non-zero" << std::endl; }
typedef void function_type();
function_type& f(int i)
{
if (i == 0) {
return zero;
}
else {
return non_zero;
}
}
int main(int argc, char* argv[])
{
int ar[2] = {0, 1};
typedef boost::transform_iterator<function_type&(*)(int), int*> iterator;
iterator it_0 = boost::make_transform_iterator(ar + 0, f);
iterator it_1 = boost::make_transform_iterator(ar + 1, f);
(*it_0)();
(*it_1)();
return 0;
}
But this code does not compile:
#include <iostream>
#include <boost/iterator/transform_iterator.hpp>
#include <boost/range/iterator_range.hpp>
void zero() { std::cout << "zero" << std::endl; }
void non_zero() { std::cout << "non-zero" << std::endl; }
typedef void function_type();
function_type& f(int i)
{
if (i == 0) {
return zero;
}
else {
return non_zero;
}
}
int main(int argc, char* argv[])
{
int ar[2] = {0, 1};
typedef boost::transform_iterator<function_type&(*)(int), int*> iterator;
typedef boost::iterator_range<iterator> range;
range rng(
boost::make_transform_iterator(ar, f)
, boost::make_transform_iterator(ar + 2, f)
);
rng[0]();
rng[1]();
return 0;
}
This is because iterator_range does not accept iterators having "reference to function type" as reference nested type.
Patch attached. Tested on gcc-4.7 and clang trunk.
Attachments (1)
Change History (4)
by , 9 years ago
| Attachment: | allow_func_ref.patch added |
|---|
comment:1 by , 9 years ago
| Component: | iterator → range |
|---|---|
| Owner: | changed from to |
comment:2 by , 9 years ago
| Status: | new → assigned |
|---|
comment:3 by , 9 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
