Advance Function Registration - Manak-org/Manak GitHub Wiki

##Registration of Templatized Functions With overloaded templatized functions the template substitution becomes ambiguous. To remove this ambiguity in case of templatized functions specific template signature must be given.

template<typename T>
int fun(T a)
{
  Code;
}

MANAK_ADD_CASE(MANAK_CREATE_BENCHMARK_WITH_TEMPLATE(B1, fun<size_t>)->AddArgs(1000));

##Overloaded Function Registration In case of overloaded functions, a static cast has to be used to determine the correct signature.

int fun(int a)
{
  Code;
}
int fun(double b)
{
  Code;
}

MANAK_ADD_CASE(MANAK_BENCHMARK_CASE(B1, static_cast<int(&)(int)>(fun)));

##Registration of Class Member Functions Static class functions can be directly passed.

class A
{
 public:
  static void fun()
  {
    Code;
  }
};

MANAK_ADD_CASE(MANAK_BENCHMARK_CASE(B1, A::fun));

The use of non static members is little complex. Manak provides a useful function manak::utils::BindToObject for that. This function accepts class member function pointer as first argument and pointer to class object as second and returns a non class member function which can be directly passed to any macro.

With manual registration -

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

bool manual_init()
{
  A* a = new A();
  manak::BenchmarkSuite::GetMasterSuite()->AddCase(MANAK_CREATE_BENCHMARK_WITH_TEMPLATE(B1, manak::utils::BindToObject(&A::fun, a))->AddArgs(1000));
}

In this case it is important to assign memory in heap as the actual call to this registered function happens after the execution of initialization.

With auto registration -

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

A* Test()
{
  return new A();
} 

MANAK_ADD_CASE(MANAK_CREATE_BENCHMARK_WITH_TEMPLATE(B1, manak::utils::BindToObject(&A::fun, Test()))->AddArgs(1000));
⚠️ **GitHub.com Fallback** ⚠️