1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| #include <vector>
#include <iostream>
class Vertex
{
public:
void doIt(int r, int g, int b, int a) const
{
std::cout << "doIt(int r, int g, int b, int a)" << std::endl;
}
void doIt(int r, int g, int b) const
{
std::cout << "doIt(int r, int g, int b)" << std::endl;
}
void doIt() const
{
std::cout << "doIt()" << std::endl;
}
};
typedef void (Vertex::*FctWith4Args)(int r, int g, int b, int a) const;
struct FunctionWithRgba
{
FunctionWithRgba(FctWith4Args memFunPtr, int r, int g, int b, int a) :
r(r), g(g), b(b), a(a), memFunPtr(memFunPtr)
{}
void operator()(Vertex const&v)
{
return ((v).*(memFunPtr))(r, g, b, a);
}
int r;
int g;
int b;
int a;
FctWith4Args memFunPtr;
};
template <class F>
void forEachVertex(std::vector<Vertex> & v, F f)
{
for (std::vector<Vertex>::iterator it = v.begin();
it != v.end() ;
++it)
{
f(*it);
}
}
int main()
{
std::vector<Vertex> v;
v.push_back(Vertex());
v.push_back(Vertex());
v.push_back(Vertex());
forEachVertex(v, FunctionWithRgba(&Vertex::doIt, 0, 1, 2, 3));
} |