On 7/28/2011 4:10 AM, Nathan Ridge wrote:
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
struct result { typedef T type; }; then transform iterator will deduce its return type to be a reference:
typedef typename ia_dflt_help< Reference , result_of
>::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
struct result { typedef T type; }; (and possibly add a non-const reference version if necessary).
Regards, Nate.
Many thanks for the explanation.
Perhaps that should be added to
http://www.boost.org/doc/libs/1_47_0/libs/utility/utility.htm#result_of, or replace the
struct result