Skip to Content
C++ Reactive Programming
book

C++ Reactive Programming

by Praseed Pai, Peter Abraham
June 2018
Intermediate to advanced
348 pages
8h 45m
English
Packt Publishing
Content preview from C++ Reactive Programming

Function wrappers

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){} ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Functional Programming in C++

Functional Programming in C++

Ivan Cukic

Publisher Resources

ISBN: 9781788629775Supplemental Content