Opened 12 years ago

Last modified 9 years ago

#4969 new Bugs

transform_iterator won't work with non-const operator() call for function object

Reported by: zhuo.qiang@… Owned by: jeffrey.hellrung
Milestone: To Be Determined Component: iterator
Version: Boost 1.45.0 Severity: Regression
Keywords: Cc:

Description

transform_iterator declare it's copied function object as:

    UnaryFunc m_f;

And it's dereference function as:

    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:

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.

    UnaryFunc mutable m_f;

Change History (4)

comment:1 by prabhu.swain@…, 12 years ago

Cc: prabhu.swain@… added

comment:2 by prabhu.swain@…, 12 years ago

Cc: prabhu.swain@… removed

comment:3 by Dave Abrahams, 10 years ago

Owner: changed from Dave Abrahams to jeffrey.hellrung

comment:4 by anonymous, 9 years ago

Please prioritize this ticket. With C++11 mutable lambdas (for which the Standard mandates a non-const operator()) this problem becomes much more frequent.

Note: See TracTickets for help on using tickets.