[Boost-bugs] [Boost C++ Libraries] #4969: transform_iterator won't work with non-const operator() call for function object

Subject: [Boost-bugs] [Boost C++ Libraries] #4969: transform_iterator won't work with non-const operator() call for function object
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-12-09 01:56:03


#4969: transform_iterator won't work with non-const operator() call for function
object
----------------------------------+-----------------------------------------
 Reporter: zhuo.qiang@… | Owner: dave
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: iterator
  Version: Boost 1.45.0 | Severity: Regression
 Keywords: |
----------------------------------+-----------------------------------------
 transform_iterator declare it's copied function object as:
 {{{#!c++
     UnaryFunc m_f;
 }}}

 And it's dereference function as:
 {{{#!c++
     typename super_t::reference dereference() const
     { return m_f(*this->base()); }
 }}}
 which makes it impossible to cooperate with function object with non-const
 operator() overloading, and and it will also make transformed adaptor in
 boost::range not work:
 {{{#!c++
 struct Fun
 {
     typedef bool result_type;

     bool operator()(int a)
     {
         return a != 1;
     }
 };
     Fun f;
     boost::find(all|boost::adaptors::transformed(f), true);
 }}}

 A boost::ref won't work here since the result has no result_type defined

 And the only solution would be using a boost::function to hold the
 original function object, however, doing so will give unnecessary run time
 cost.

 I suggest change the UnaryFunc m_f; definition to mutable, so that it will
 work with non-const functor.
 {{{#!c++
     UnaryFunc mutable m_f;
 }}}

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