Boost logo

Boost :

From: Levente Farkas (lfarkas_at_[hidden])
Date: 2001-10-04 09:41:16

this "simple" example cant compile on MSVC 6sp5. is there any chance to
compile it or better to give up.

ps. anyway such a MemberAccess or MemberSelector functor would be useful
to add to boost (this's a general form of the elector can be found in
the projection_iterator's example section).
#include <boost/iterator_adaptors.hpp>
#include <boost/functional.hpp>
#include <algorithm>
#include <vector>
#include <list>

template<typename Class, typename T>
class MemberAccess : public std::unary_function<Class, T>
  typedef T Class::* Member;
  MemberAccess(Member m) : member(m) {}
  const T& operator()(const Class& obj) const { return obj.*member; }
  T& operator()(Class& obj) const { return obj.*member; }
  Member member;

struct A
  A() : x(0) {}
  double x;

int main()
  std::vector<double> v(10);
  std::list<A> a(v.size());
  std::copy(v.begin(), v.end(),
                                            MemberAccess<A, double>(&A::x)));
  return 0;
 -- Levente "Si vis pacem para bellum!"

Boost list run by bdawes at, gregod at, cpdaniel at, john at