small addition to functional

Hi all, I think since member functions can be wrapped up as functors, why not same for member data? Therefore, I think this could be a useful addition to functional: // wraps a member data into a functor // // very useful with boost::bind template<class type, class member_type> class mem_data_t { typedef member_type type::*data; public: // FIXME allow also having non-const result-type typedef const member_type & result_type; mem_data_t( data d) : m_data(d) {} const member_type & operator()( const type & val) const { return val.*m_data; } member_type & operator()( type & val) const { return val.*m_data; } private: data m_data; }; template<class type, class member_type> mem_data_t<type,member_type> mem_data(member_type type::*data) { return mem_data_t<type,member_type>(data); } It can be improved, but roughly, that's it. What do you think? Best, John

John Torjo wrote:
Hi all,
I think since member functions can be wrapped up as functors, why not same for member data? Therefore, I think this could be a useful addition to functional:
// wraps a member data into a functor // // very useful with boost::bind
meant boost::transform_iterator :), but it's useful for bind also ;)
participants (1)
-
John Torjo