Index: boost/iterator/transform_iterator.hpp =================================================================== --- boost/iterator/transform_iterator.hpp (revision 61317) +++ boost/iterator/transform_iterator.hpp (working copy) @@ -14,7 +14,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -130,15 +132,30 @@ {} UnaryFunc functor() const - { return m_f; } + { return unwrap_functor(m_f); } private: typename super_t::reference dereference() const - { return m_f(*this->base()); } + { return unwrap_functor(m_f)(*this->base()); } + UnaryFunc const& unwrap_functor(UnaryFunc const& t) const + { return t; } + + UnaryFunc const& unwrap_functor(optional const& t) const + { return *t; } + + typedef typename mpl::if_< + mpl::and_< + is_class + , mpl::not_ > + > + , optional + , UnaryFunc + >::type unary_functor_type; + // Probably should be the initial base class so it can be // optimized away via EBO if it is an empty class. - UnaryFunc m_f; + unary_functor_type m_f; }; template