|
Boost : |
From: Levente Farkas (lfarkas_at_[hidden])
Date: 2001-10-04 09:41:16
hi,
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).
yours.
-----------------------
#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>
{
public:
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; }
protected:
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(),
boost::make_projection_iterator(a.begin(),
MemberAccess<A, double>(&A::x)));
return 0;
}
-----------------------
-- Levente "Si vis pacem para bellum!"
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk