-4

I have an utility function which takes two values and does something on another object if two values meet a certain criteria.

So, the utility function has to take a member function as a std:function and also sometimes as a free flowing function.

class A
{
    public:
    void fun(int a) {}
};

template <typename T>
bool ifSet(T a, T b, std::function<void(T)> f )
{
    if (a == b) return false;
    else return f(b);
}

int main() {
    auto p = std::make_shared<A>(new A);
    std::cout<< ifSet(10, 10, std::bind(A::fun, p, std::placeholders::_1));

The above code is my dummy implementation, but doesn't work. Can someone suggest me a better code ?

asit_dhal
  • 1,239
  • 19
  • 35

1 Answers1

2

Your

std::function<void(T)> f

return a void and you use it as return for bool ifSet() function

Moia
  • 2,216
  • 1
  • 12
  • 34