Topic: why there is no function named mem_data in c++ standard?


Author: Pete Becker <petebecker@acm.org>
Date: Mon, 16 Oct 2006 16:17:27 CST
Raw View
Leo Jay wrote:
> since there is a function named mem_fun in c++ standard which returns
> an adptor for member functions, i'd like to know, why there is no
> function named mem_data which may return an adptor for member data?
>

Its name is std::tr1::mem_fn. Also std::tr1::bind. In addition, the
function call operators for std::tr1::reference_wrapper and
std::tr1:function also treat a pointer to member data as a callable
object. For more details, see chapter 6 of my book, "The Standard C++
Library Extensions."

--

 -- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Leo Jay" <Python.LeoJay@gmail.com>
Date: Mon, 16 Oct 2006 12:14:35 CST
Raw View
since there is a function named mem_fun in c++ standard which returns
an adptor for member functions, i'd like to know, why there is no
function named mem_data which may return an adptor for member data?

if there was one, we could do something like this:

typedef pair<int, double> IDPAIR;
vector<IDPAIR> vct;

// get the sum of the first elements
int sf = sum(vct.begin(), vct.end(), mem_data(&IDPAIR::first));

// get the sum of the second elements
double ss = sum(vct.begin(), vct.end(), mem_data(&IDPAIR::second));


am i right?

thanks,

--
Best Regards,
Leo Jay

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]