V
vulpes
This similar situation will explain somewhat, what I want to do:
class X {
public:
X() : map_(*this) {}
bool operator() (int a, int b) { return goodStuff(a) <
goodStuff(b); }
int goodStuff(int a) { ... }
private:
map<int, int, X> map_;
};
Why do I want this? Because the goodStuff function is already there
and I don't want to write it twice. This piece of code doesn't work as
one would expect. I also tried doing things like
class X {
public:
X() : map_( ptr_fun(&X::stuff) ) {}
bool stuff(int a, int b) const { return goodStuff(a) <
goodStuff(b); }
private:
map< int, int, binary_function<int, int, bool> > map_;
};
but this works neither. Is there a way to do this thing. The X objects
are a pain to construct (lots of big stuff in 'em) so I don't want to
generate them anymore than I have to. I guess that second could be
made to work if the goodStuff would be static, but it ain't.
This isn't a stopper problem, I know a way around this (problem-
specific), but it stinks. I want to know how to do this "the way it
should be done".
class X {
public:
X() : map_(*this) {}
bool operator() (int a, int b) { return goodStuff(a) <
goodStuff(b); }
int goodStuff(int a) { ... }
private:
map<int, int, X> map_;
};
Why do I want this? Because the goodStuff function is already there
and I don't want to write it twice. This piece of code doesn't work as
one would expect. I also tried doing things like
class X {
public:
X() : map_( ptr_fun(&X::stuff) ) {}
bool stuff(int a, int b) const { return goodStuff(a) <
goodStuff(b); }
private:
map< int, int, binary_function<int, int, bool> > map_;
};
but this works neither. Is there a way to do this thing. The X objects
are a pain to construct (lots of big stuff in 'em) so I don't want to
generate them anymore than I have to. I guess that second could be
made to work if the goodStuff would be static, but it ain't.
This isn't a stopper problem, I know a way around this (problem-
specific), but it stinks. I want to know how to do this "the way it
should be done".