June 2018
Intermediate to advanced
348 pages
8h 45m
English
Function wrappers are classes that can wrap any functions, function objects, or Lambdas into a copiable object. The type of the wrapper depends upon the function prototype of the class. std::function(<prototype>) from the <functional> header represents a function wrapper:
//---------------- FuncWrapper.cpp Requires C++ 17 (-std=c++1z )#include <functional>#include <iostream>using namespace std;//-------------- Simple Function callvoid PrintNumber(int val){ cout << val << endl; }// ------------------ A class which overloads function operatorstruct PrintNumber { void operator()(int i) const { std::cout << i << '\n';}};//------------ To demonstrate the usage of method callstruct FooClass { int number; FooClass(int pnum) : number(pnum){} ...