Run Code  | API  | Code Wall  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

C++11 Cpp11 Functor example in modern C++

Language: Layout:
+ ] Compiler args + ] Show input
Compilation time: 1.43 sec, absolute running time: 0.23 sec, cpu time: 0.16 sec, memory peak: 3 Mb, absolute service time: 1,67 sec 
fork mode |  history
a = 3 ; b = 4
fun1(3.0) = 13
fun1(4.0) = 16
fun1(5.0) = 19
=======================
a = 2 ; b = 3 ; c = 4
fun2(3.0) = 31
fun2(4.0) = 48
fun2(5.0) = 69
======= [1] Client Code using dynamic polymorphism  ================
 -----> Tabulating fun1
     0.000     4.000
     1.000     7.000
     2.000    10.000
     3.000    13.000
     4.000    16.000
     5.000    19.000
 -----> Tabulating fun2
     0.000     4.000
     1.000     9.000
     2.000    18.000
     3.000    31.000
     4.000    48.000
     5.000    69.000
======= [2] Client Code using dynamic polymorphism  ================
     0.000     4.000     4.000
     1.000     7.000     9.000
     2.000    10.000    18.000
     3.000    13.000    31.000
     4.000    16.000    48.000
     5.000    19.000    69.000
======= Client Code using static polymorphism (template)  ================
 -----> Tabulating fun1
     0.000     4.000
     1.000     7.000
     2.000    10.000
     3.000    13.000
     4.000    16.000
     5.000    19.000
 -----> Tabulating fun2
     0.000     4.000
     1.000     9.000
     2.000    18.000
     3.000    31.000
     4.000    48.000
     5.000    69.000
 -----> Tabulating lambda function f(x) = x * x
     0.000     0.000
     1.000     1.000
     2.000     4.000
     3.000     9.000
     4.000    16.000
     5.000    25.000
 -----> Tabulating ordinary function f(x) = 3 * x
     0.000     0.000
     1.000     3.000
     2.000     6.000
     3.000     9.000
     4.000    12.000
     5.000    15.000
 -----> Tabulating ordinary function f(x) = exp(x)
     0.000     1.000
     1.000     2.718
     2.000     7.389
     3.000    20.086
     4.000    54.598
     5.000   148.413
======= Client Code using C++11 lambda std::function  ================
     0.000     4.000     4.000     1.000     0.000
     1.000     7.000     9.000     2.718     3.000
     2.000    10.000    18.000     7.389     6.000
     3.000    13.000    31.000    20.086     9.000
     4.000    16.000    48.000    54.598    12.000
     5.000    19.000    69.000   148.413    15.000

    
                
λ
.NET NoSQL database for rapid development