Boost logo

Boost Users :

Subject: Re: [Boost-users] Odd Warning in transform_iterator.hpp ?
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2011-07-28 05:10:30


> I'm using the current Boost library on Microsoft Visual Studio 2005. I'm getting a
> warning on line 121 of transform_iterator.hpp, complaining "returning address of local
> variable or temporary". The line in question is the body of this function:
>
> typename super_t::reference dereference() const
> { return m_f(*this->base()); }
>
> My m_f supplied to the template is ordinary enough; it returns a value.

Is your m_f a function object that uses result_of protocol to declare
its return value?
 
It may be that while its operator() returns a value, its result<> is telling
transform_iterator that it returns a reference.
 
For example, if its result<> looks like this:
 
template <typename> struct result;
template <typename F, typename T>
struct result<F(T)>
{
    typedef T type;
};
 
then transform iterator will deduce its return type to be a reference:
 
typedef typename ia_dflt_help<
            Reference
          , result_of<UnaryFunc(typename std::iterator_traits<Iterator>::reference)>
>::type reference;

and it will use this as the return type of operator*. Hence the warning.
 
Instead, you need to declare result<> like this:
 
template <typename> struct result;
template <typename F, typename T>
struct result<F(const T&)>
{
    typedef T type;
};
 
(and possibly add a non-const reference version if necessary).
 
Regards,
Nate.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net