June 2018
Intermediate to advanced
348 pages
8h 45m
English
One advantage of Lambdas is you can compose two functions together to create a composition of functions as you do in mathematics (read about function composition in the context of mathematics and functional programming using favorite search engine). The following program demonstrates the idea. This is a toy implementation and writing a general-purpose implementation is beyond the scope of this chapter:
//------------ Compose.cpp//----- g++ -std=c++1z Compose.cpp#include <iostream>using namespace std;//---------- base case compile time recursion//---------- stops heretemplate <typename F, typename G>auto Compose(F&& f, G&& g){ return [=](auto x) { return f(g(x)); };}//----- Performs ...