J
JohanS
I have been trying to create this function for some time now. Reading
about pointers to member functions until my head hurts. Now i did it
like you see below and i am now wondering. What am i missing here?
What am i not thinking about? Cause this way was to easy. Will i get
in trouble in the future doing it this way? Feedback appreciated! Is
there something that can be done alot better (I'm not looking for a
totally different way of doing it)?
#define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember))
namespace misc {
template <typename Iterator, typename Function>
int count(Iterator start, Iterator end, Function fun, int value)
{
int temp = 0;
while(start != end)
{
if(CALL_MEMBER_FN(*start, fun) () == value)
++temp;
++start;
}
return temp;
}}
// In main -> works.. wohoo
cout << misc::count(vl.begin(), vl.end(),
&SomeClass::SomeMemberFunction, 3);
about pointers to member functions until my head hurts. Now i did it
like you see below and i am now wondering. What am i missing here?
What am i not thinking about? Cause this way was to easy. Will i get
in trouble in the future doing it this way? Feedback appreciated! Is
there something that can be done alot better (I'm not looking for a
totally different way of doing it)?
#define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember))
namespace misc {
template <typename Iterator, typename Function>
int count(Iterator start, Iterator end, Function fun, int value)
{
int temp = 0;
while(start != end)
{
if(CALL_MEMBER_FN(*start, fun) () == value)
++temp;
++start;
}
return temp;
}}
// In main -> works.. wohoo
cout << misc::count(vl.begin(), vl.end(),
&SomeClass::SomeMemberFunction, 3);