mirror of
https://github.com/VictorEijkhout/TheArtOfHPC_vol3_cppf08programming.git
synced 2026-01-24 22:44:48 +09:00
30 lines
702 B
C++
30 lines
702 B
C++
/****************************************************************
|
|
****
|
|
**** This file belongs with the course
|
|
**** Introduction to Scientific Programming in C++/Fortran2003
|
|
**** copyright 2018-2023 Victor Eijkhout eijkhout@tacc.utexas.edu
|
|
****
|
|
**** lambdarecur.cxx : lambda example
|
|
****
|
|
****************************************************************/
|
|
|
|
#include <iostream>
|
|
using std::cout;
|
|
|
|
int main() {
|
|
|
|
auto ipower =
|
|
[] (int base,int power) {
|
|
auto iipower =
|
|
[] ( auto&& self, int base,int power ) {
|
|
if (power==0) return 1;
|
|
else return base * self(self,base,power-1);
|
|
};
|
|
return iipower(iipower,base,power);
|
|
} ;
|
|
|
|
cout << ipower(2,5) << '\n';
|
|
|
|
return 0;
|
|
}
|