Subject: [Boost-bugs] [Boost C++ Libraries] #9072: `iterator_range` does not accept iterators having "reference to function type" as `reference` nested type
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-08-31 12:49:15
#9072: `iterator_range` does not accept iterators having "reference to function
type" as `reference` nested type
-------------------------------------+------------------------------
Reporter: michel | Owner: jeffrey.hellrung
Type: Patches | Status: new
Milestone: To Be Determined | Component: iterator
Version: Boost Development Trunk | Severity: Problem
Keywords: |
-------------------------------------+------------------------------
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.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/9072> 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:14 UTC