SlideShare a Scribd company logo
[](){}();
Or How I Learned To Stop Worrying and Love the
Lambda
Pat Viafore
HSV.cpp Meetup
3/15/2017
Lambda
Expressions
Lambda Expressions
Lambda Calculus
Church-Turing Thesis
Conversion and Reduction
Complicated Mathematics
Functional Programming
Underpinnings of Computer Science
Lisp?
Lambda Expressions in C++
Anonymous
Functions
[](){}
[](){}
[](){}
Function
Body
void print(std::function<bool()> func)
{
std::string str = func() ? "true" : "false";
std::cout << str << “n”;
}
auto isFiveGreaterThanThree = [](){ return 5 > 3; };
print(isFiveGreaterThanThree);
[](){}
Parameters
Function
Body
void print(int param, std::function<bool(int)> func)
{
std::string str = func(param) ? "true" : "false";
std::cout << str << “n”;
}
auto isGreaterThanThree = [](int num){ return num > 3; };
print(5, isGreaterThanThree);
[](){}
Capture
List
Parameters
Function
Body
void print(int num, std::function<bool(int)> func)
{
std::string str = func(num) ? "true" : "false";
std::cout << str << “n”;
}
int target = 3;
auto isGreaterThan = [target](int n){ return n > target; };
target = 6;
print(5, isGreaterThan);
Capture List
By Value By Reference
[this]
[a,b]
[=]
[&a,&b]
[&]
Prefer Explicit Captures Over
Default Captures
class A {
public:
int x;
A(): x(10) {}
std::function<bool()> getLambda()
{
return [=](){ return x+2; };
}
};
int main()
{
A* a = new A();
auto lambda = a->getLambda();
delete a;
lambda();
}
This is implicitly this->x. The this
parameter is what gets captured, not
x.
class A {
public:
int x;
A(): x(10) {}
std::function<bool()> getLambda()
{
return [copy=x](){ return copy+2; };
}
};
int main()
{
A* a = new A();
auto lambda = a->getLambda();
delete a;
lambda();
}
C++14 gives us init captures,
where we can initialize the
variables we capture (useful for
any non-local captures)
Why?
Dependency Injection
Pass a function to inject a dependency
Functional Programming Styles
Mapping and Filtering just got a whole lot easier
Algorithm Library
auto isSpecial = [](MacAddress& mac){ return MacAddress::ItuAddress == mac; };
any_of(macs.begin(), macs.end(), isSpecial);
count_if(macs.begin(), macs.end(), isSpecial);
replace_if(macs.begin(), macs.end(), isSpecial, MacAddress::BlankMacAddress);
sort(ips.begin(), ips.end(), [](IpAddressV4& ip1, IpAddressV4& ip2)
{ return ip1.getNetworkByteOrder() < ip2.getNetworkByteOrder()); });
[](){}
Capture
List
Parameters
Function
Body
();
Twitter:
@PatViaforever
Ad

More Related Content

What's hot (20)

XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015
XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015
XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015
CODE BLUE
 
PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?
Sam Thomas
 
Web-servers & Application Hacking
Web-servers & Application HackingWeb-servers & Application Hacking
Web-servers & Application Hacking
Raghav Bisht
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
Edureka!
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best Practices
Theo Jungeblut
 
Golang (Go Programming Language)
Golang (Go Programming Language)Golang (Go Programming Language)
Golang (Go Programming Language)
ShubhamMishra485
 
Building Advanced XSS Vectors
Building Advanced XSS VectorsBuilding Advanced XSS Vectors
Building Advanced XSS Vectors
Rodolfo Assis (Brute)
 
PurpleSharp BlackHat Arsenal Asia
PurpleSharp BlackHat Arsenal AsiaPurpleSharp BlackHat Arsenal Asia
PurpleSharp BlackHat Arsenal Asia
Mauricio Velazco
 
inheritance
inheritanceinheritance
inheritance
Amir_Mukhtar
 
F#によるFunctional Programming入門
F#によるFunctional Programming入門F#によるFunctional Programming入門
F#によるFunctional Programming入門
bleis tift
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
Mario Fusco
 
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
Christopher Frohoff
 
Go lang
Go langGo lang
Go lang
Suelen Carvalho
 
The lazy programmer's guide to writing thousands of tests
The lazy programmer's guide to writing thousands of testsThe lazy programmer's guide to writing thousands of tests
The lazy programmer's guide to writing thousands of tests
Scott Wlaschin
 
Rest api with Python
Rest api with PythonRest api with Python
Rest api with Python
Santosh Ghimire
 
Deep drive into rust programming language
Deep drive into rust programming languageDeep drive into rust programming language
Deep drive into rust programming language
Vigneshwer Dhinakaran
 
Kotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime PerformanceKotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime Performance
intelliyole
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
intelliyole
 
PyCon 2017 예제로 살펴보는 PyQt
PyCon 2017 예제로 살펴보는 PyQtPyCon 2017 예제로 살펴보는 PyQt
PyCon 2017 예제로 살펴보는 PyQt
덕규 임
 
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Domain Driven Design with the F# type System -- F#unctional Londoners 2014Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Scott Wlaschin
 
XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015
XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015
XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015
CODE BLUE
 
PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?
Sam Thomas
 
Web-servers & Application Hacking
Web-servers & Application HackingWeb-servers & Application Hacking
Web-servers & Application Hacking
Raghav Bisht
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
Edureka!
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best Practices
Theo Jungeblut
 
Golang (Go Programming Language)
Golang (Go Programming Language)Golang (Go Programming Language)
Golang (Go Programming Language)
ShubhamMishra485
 
PurpleSharp BlackHat Arsenal Asia
PurpleSharp BlackHat Arsenal AsiaPurpleSharp BlackHat Arsenal Asia
PurpleSharp BlackHat Arsenal Asia
Mauricio Velazco
 
F#によるFunctional Programming入門
F#によるFunctional Programming入門F#によるFunctional Programming入門
F#によるFunctional Programming入門
bleis tift
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
Mario Fusco
 
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
Christopher Frohoff
 
The lazy programmer's guide to writing thousands of tests
The lazy programmer's guide to writing thousands of testsThe lazy programmer's guide to writing thousands of tests
The lazy programmer's guide to writing thousands of tests
Scott Wlaschin
 
Deep drive into rust programming language
Deep drive into rust programming languageDeep drive into rust programming language
Deep drive into rust programming language
Vigneshwer Dhinakaran
 
Kotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime PerformanceKotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime Performance
intelliyole
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
intelliyole
 
PyCon 2017 예제로 살펴보는 PyQt
PyCon 2017 예제로 살펴보는 PyQtPyCon 2017 예제로 살펴보는 PyQt
PyCon 2017 예제로 살펴보는 PyQt
덕규 임
 
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Domain Driven Design with the F# type System -- F#unctional Londoners 2014Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Scott Wlaschin
 

Viewers also liked (17)

BDD to the Bone: Using Behave and Selenium to Test-Drive Web Applications
BDD to the Bone: Using Behave and Selenium to Test-Drive Web ApplicationsBDD to the Bone: Using Behave and Selenium to Test-Drive Web Applications
BDD to the Bone: Using Behave and Selenium to Test-Drive Web Applications
Patrick Viafore
 
мадоу № 82
мадоу № 82мадоу № 82
мадоу № 82
Skazka82
 
Presentació pati
Presentació patiPresentació pati
Presentació pati
Esther Dalmau Palomar
 
Magazine front covers 4
Magazine front covers 4Magazine front covers 4
Magazine front covers 4
ah05007283
 
Virus360 supersaiyajinlegendario.exe
Virus360 supersaiyajinlegendario.exeVirus360 supersaiyajinlegendario.exe
Virus360 supersaiyajinlegendario.exe
Mery Noguera
 
la comunicación en la sociedad
la comunicación en la sociedad la comunicación en la sociedad
la comunicación en la sociedad
maria camila suarez betancur
 
Guide hygiene informatique_anssi
Guide hygiene informatique_anssiGuide hygiene informatique_anssi
Guide hygiene informatique_anssi
kabengniga ibrahima soro
 
Industrial Equipment.
Industrial Equipment. Industrial Equipment.
Industrial Equipment.
Elena Vishnevskaya
 
Basic functionalities of ez cast dongle
Basic functionalities of ez cast dongleBasic functionalities of ez cast dongle
Basic functionalities of ez cast dongle
wifi ezcast dongle
 
Dp1
Dp1Dp1
Dp1
Hemer Hadyn Calderon Alvites
 
TRATAMIENTO AGUA EN HEMODIALISIS
TRATAMIENTO AGUA EN HEMODIALISISTRATAMIENTO AGUA EN HEMODIALISIS
TRATAMIENTO AGUA EN HEMODIALISIS
gustavo diaz nuñez
 
PRINCIPIOS BIOFISICOS DE LA HEMODIALISIS
PRINCIPIOS BIOFISICOS DE LA HEMODIALISISPRINCIPIOS BIOFISICOS DE LA HEMODIALISIS
PRINCIPIOS BIOFISICOS DE LA HEMODIALISIS
gustavo diaz nuñez
 
Lagopusで試すFW
Lagopusで試すFWLagopusで試すFW
Lagopusで試すFW
Tomoya Hibi
 
FARMACOCINETICA: ABSORCIÓN Y DISTRIBUCIÓN
FARMACOCINETICA: ABSORCIÓN Y DISTRIBUCIÓN FARMACOCINETICA: ABSORCIÓN Y DISTRIBUCIÓN
FARMACOCINETICA: ABSORCIÓN Y DISTRIBUCIÓN
evelyn sagredo
 
Técnicas del coaching
Técnicas del coachingTécnicas del coaching
Técnicas del coaching
Rondonjhenyfer
 
CArcMOOC 06.04 - Dynamic optimizations
CArcMOOC 06.04 - Dynamic optimizationsCArcMOOC 06.04 - Dynamic optimizations
CArcMOOC 06.04 - Dynamic optimizations
Alessandro Bogliolo
 
BDD to the Bone: Using Behave and Selenium to Test-Drive Web Applications
BDD to the Bone: Using Behave and Selenium to Test-Drive Web ApplicationsBDD to the Bone: Using Behave and Selenium to Test-Drive Web Applications
BDD to the Bone: Using Behave and Selenium to Test-Drive Web Applications
Patrick Viafore
 
мадоу № 82
мадоу № 82мадоу № 82
мадоу № 82
Skazka82
 
Magazine front covers 4
Magazine front covers 4Magazine front covers 4
Magazine front covers 4
ah05007283
 
Virus360 supersaiyajinlegendario.exe
Virus360 supersaiyajinlegendario.exeVirus360 supersaiyajinlegendario.exe
Virus360 supersaiyajinlegendario.exe
Mery Noguera
 
Basic functionalities of ez cast dongle
Basic functionalities of ez cast dongleBasic functionalities of ez cast dongle
Basic functionalities of ez cast dongle
wifi ezcast dongle
 
TRATAMIENTO AGUA EN HEMODIALISIS
TRATAMIENTO AGUA EN HEMODIALISISTRATAMIENTO AGUA EN HEMODIALISIS
TRATAMIENTO AGUA EN HEMODIALISIS
gustavo diaz nuñez
 
PRINCIPIOS BIOFISICOS DE LA HEMODIALISIS
PRINCIPIOS BIOFISICOS DE LA HEMODIALISISPRINCIPIOS BIOFISICOS DE LA HEMODIALISIS
PRINCIPIOS BIOFISICOS DE LA HEMODIALISIS
gustavo diaz nuñez
 
Lagopusで試すFW
Lagopusで試すFWLagopusで試すFW
Lagopusで試すFW
Tomoya Hibi
 
FARMACOCINETICA: ABSORCIÓN Y DISTRIBUCIÓN
FARMACOCINETICA: ABSORCIÓN Y DISTRIBUCIÓN FARMACOCINETICA: ABSORCIÓN Y DISTRIBUCIÓN
FARMACOCINETICA: ABSORCIÓN Y DISTRIBUCIÓN
evelyn sagredo
 
Técnicas del coaching
Técnicas del coachingTécnicas del coaching
Técnicas del coaching
Rondonjhenyfer
 
CArcMOOC 06.04 - Dynamic optimizations
CArcMOOC 06.04 - Dynamic optimizationsCArcMOOC 06.04 - Dynamic optimizations
CArcMOOC 06.04 - Dynamic optimizations
Alessandro Bogliolo
 
Ad

Similar to Lambda Expressions in C++ (20)

The Arrow Library in Kotlin
The Arrow Library in KotlinThe Arrow Library in Kotlin
The Arrow Library in Kotlin
Garth Gilmour
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
The Software House
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
Tech_MX
 
Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0
Sheik Uduman Ali
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
Neeru Mittal
 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)
Sumant Tambe
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
Tushar B Kute
 
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjkPOEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
hanumanthumanideeph6
 
SaraPIC
SaraPICSaraPIC
SaraPIC
Sara Sahu
 
Input output functions
Input output functionsInput output functions
Input output functions
hyderali123
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf Edition
Paulo Morgado
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
Bosco Technical Training Society, Don Bosco Technical School (Aff. GGSIP University, New Delhi)
 
Csharp4 delegates lambda_and_events
Csharp4 delegates lambda_and_eventsCsharp4 delegates lambda_and_events
Csharp4 delegates lambda_and_events
Abed Bukhari
 
Alexey Tsoy Meta Programming in C++ 16.11.17
Alexey Tsoy Meta Programming in C++ 16.11.17Alexey Tsoy Meta Programming in C++ 16.11.17
Alexey Tsoy Meta Programming in C++ 16.11.17
LogeekNightUkraine
 
CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38
Bilal Ahmed
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
JAYA
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
vikram mahendra
 
Apache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheelApache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheel
tcurdt
 
Scala @ TomTom
Scala @ TomTomScala @ TomTom
Scala @ TomTom
Eric Bowman
 
.net progrmming part1
.net progrmming part1.net progrmming part1
.net progrmming part1
Dr.M.Karthika parthasarathy
 
The Arrow Library in Kotlin
The Arrow Library in KotlinThe Arrow Library in Kotlin
The Arrow Library in Kotlin
Garth Gilmour
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
The Software House
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
Tech_MX
 
Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0
Sheik Uduman Ali
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
Neeru Mittal
 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)
Sumant Tambe
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
Tushar B Kute
 
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjkPOEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
hanumanthumanideeph6
 
Input output functions
Input output functionsInput output functions
Input output functions
hyderali123
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf Edition
Paulo Morgado
 
Csharp4 delegates lambda_and_events
Csharp4 delegates lambda_and_eventsCsharp4 delegates lambda_and_events
Csharp4 delegates lambda_and_events
Abed Bukhari
 
Alexey Tsoy Meta Programming in C++ 16.11.17
Alexey Tsoy Meta Programming in C++ 16.11.17Alexey Tsoy Meta Programming in C++ 16.11.17
Alexey Tsoy Meta Programming in C++ 16.11.17
LogeekNightUkraine
 
CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38
Bilal Ahmed
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
JAYA
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
vikram mahendra
 
Apache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheelApache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheel
tcurdt
 
Ad

More from Patrick Viafore (12)

Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
Patrick Viafore
 
User-Defined Types.pdf
User-Defined Types.pdfUser-Defined Types.pdf
User-Defined Types.pdf
Patrick Viafore
 
The Most Misunderstood Line In Zen Of Python.pdf
The Most Misunderstood Line In Zen Of Python.pdfThe Most Misunderstood Line In Zen Of Python.pdf
The Most Misunderstood Line In Zen Of Python.pdf
Patrick Viafore
 
Robust Python.pptx
Robust Python.pptxRobust Python.pptx
Robust Python.pptx
Patrick Viafore
 
Tip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python TypingTip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python Typing
Patrick Viafore
 
RunC, Docker, RunC
RunC, Docker, RunCRunC, Docker, RunC
RunC, Docker, RunC
Patrick Viafore
 
DevSpace 2018 - Practical Computer Science: What You Need To Know Without Th...
 DevSpace 2018 - Practical Computer Science: What You Need To Know Without Th... DevSpace 2018 - Practical Computer Science: What You Need To Know Without Th...
DevSpace 2018 - Practical Computer Science: What You Need To Know Without Th...
Patrick Viafore
 
Controlling Raspberry Pis With Your Phone Using Python
Controlling Raspberry Pis With Your Phone Using PythonControlling Raspberry Pis With Your Phone Using Python
Controlling Raspberry Pis With Your Phone Using Python
Patrick Viafore
 
C++17 not your father’s c++
C++17  not your father’s c++C++17  not your father’s c++
C++17 not your father’s c++
Patrick Viafore
 
Building a development community within your workplace
Building a development community within your workplaceBuilding a development community within your workplace
Building a development community within your workplace
Patrick Viafore
 
Hsv.py Lightning Talk - Bottle
Hsv.py Lightning Talk - BottleHsv.py Lightning Talk - Bottle
Hsv.py Lightning Talk - Bottle
Patrick Viafore
 
Controlling the browser through python and selenium
Controlling the browser through python and seleniumControlling the browser through python and selenium
Controlling the browser through python and selenium
Patrick Viafore
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
Patrick Viafore
 
The Most Misunderstood Line In Zen Of Python.pdf
The Most Misunderstood Line In Zen Of Python.pdfThe Most Misunderstood Line In Zen Of Python.pdf
The Most Misunderstood Line In Zen Of Python.pdf
Patrick Viafore
 
Tip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python TypingTip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python Typing
Patrick Viafore
 
DevSpace 2018 - Practical Computer Science: What You Need To Know Without Th...
 DevSpace 2018 - Practical Computer Science: What You Need To Know Without Th... DevSpace 2018 - Practical Computer Science: What You Need To Know Without Th...
DevSpace 2018 - Practical Computer Science: What You Need To Know Without Th...
Patrick Viafore
 
Controlling Raspberry Pis With Your Phone Using Python
Controlling Raspberry Pis With Your Phone Using PythonControlling Raspberry Pis With Your Phone Using Python
Controlling Raspberry Pis With Your Phone Using Python
Patrick Viafore
 
C++17 not your father’s c++
C++17  not your father’s c++C++17  not your father’s c++
C++17 not your father’s c++
Patrick Viafore
 
Building a development community within your workplace
Building a development community within your workplaceBuilding a development community within your workplace
Building a development community within your workplace
Patrick Viafore
 
Hsv.py Lightning Talk - Bottle
Hsv.py Lightning Talk - BottleHsv.py Lightning Talk - Bottle
Hsv.py Lightning Talk - Bottle
Patrick Viafore
 
Controlling the browser through python and selenium
Controlling the browser through python and seleniumControlling the browser through python and selenium
Controlling the browser through python and selenium
Patrick Viafore
 

Recently uploaded (20)

Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
Let's Do Bad Things to Unsecured Containers
Let's Do Bad Things to Unsecured ContainersLet's Do Bad Things to Unsecured Containers
Let's Do Bad Things to Unsecured Containers
Gene Gotimer
 
Codingo Ltd. - Introduction - Mobile application, web, custom software develo...
Codingo Ltd. - Introduction - Mobile application, web, custom software develo...Codingo Ltd. - Introduction - Mobile application, web, custom software develo...
Codingo Ltd. - Introduction - Mobile application, web, custom software develo...
Codingo
 
Aligning Projects to Strategy During Economic Uncertainty
Aligning Projects to Strategy During Economic UncertaintyAligning Projects to Strategy During Economic Uncertainty
Aligning Projects to Strategy During Economic Uncertainty
OnePlan Solutions
 
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptxThe-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
james brownuae
 
Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??
Web Designer
 
Albert Pintoy - A Distinguished Software Engineer
Albert Pintoy - A Distinguished Software EngineerAlbert Pintoy - A Distinguished Software Engineer
Albert Pintoy - A Distinguished Software Engineer
Albert Pintoy
 
How to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryErrorHow to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryError
Tier1 app
 
How to Create a Crypto Wallet Like Trust.pptx
How to Create a Crypto Wallet Like Trust.pptxHow to Create a Crypto Wallet Like Trust.pptx
How to Create a Crypto Wallet Like Trust.pptx
riyageorge2024
 
Catching Wire; An introduction to CBWire 4
Catching Wire; An introduction to CBWire 4Catching Wire; An introduction to CBWire 4
Catching Wire; An introduction to CBWire 4
Ortus Solutions, Corp
 
Shift Right Security for EKS Webinar Slides
Shift Right Security for EKS Webinar SlidesShift Right Security for EKS Webinar Slides
Shift Right Security for EKS Webinar Slides
Anchore
 
Quasar Framework Introduction for C++ develpoers
Quasar Framework Introduction for C++ develpoersQuasar Framework Introduction for C++ develpoers
Quasar Framework Introduction for C++ develpoers
sadadkhah
 
Best HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRMBest HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRM
accordHRM
 
Multi-Agent Era will Define the Future of Software
Multi-Agent Era will Define the Future of SoftwareMulti-Agent Era will Define the Future of Software
Multi-Agent Era will Define the Future of Software
Ivo Andreev
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
cram_advancedword2007version2025final.ppt
cram_advancedword2007version2025final.pptcram_advancedword2007version2025final.ppt
cram_advancedword2007version2025final.ppt
ahmedsaadtax2025
 
Bridging Sales & Marketing Gaps with IInfotanks’ Salesforce Account Engagemen...
Bridging Sales & Marketing Gaps with IInfotanks’ Salesforce Account Engagemen...Bridging Sales & Marketing Gaps with IInfotanks’ Salesforce Account Engagemen...
Bridging Sales & Marketing Gaps with IInfotanks’ Salesforce Account Engagemen...
jamesmartin143256
 
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb ClarkDeploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Peter Caitens
 
GC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance EngineeringGC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance Engineering
Tier1 app
 
Grand Theft Auto 6 PC Game Cracked Full Setup Download
Grand Theft Auto 6 PC Game Cracked Full Setup DownloadGrand Theft Auto 6 PC Game Cracked Full Setup Download
Grand Theft Auto 6 PC Game Cracked Full Setup Download
Iobit Uninstaller Pro Crack
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
Let's Do Bad Things to Unsecured Containers
Let's Do Bad Things to Unsecured ContainersLet's Do Bad Things to Unsecured Containers
Let's Do Bad Things to Unsecured Containers
Gene Gotimer
 
Codingo Ltd. - Introduction - Mobile application, web, custom software develo...
Codingo Ltd. - Introduction - Mobile application, web, custom software develo...Codingo Ltd. - Introduction - Mobile application, web, custom software develo...
Codingo Ltd. - Introduction - Mobile application, web, custom software develo...
Codingo
 
Aligning Projects to Strategy During Economic Uncertainty
Aligning Projects to Strategy During Economic UncertaintyAligning Projects to Strategy During Economic Uncertainty
Aligning Projects to Strategy During Economic Uncertainty
OnePlan Solutions
 
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptxThe-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
james brownuae
 
Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??
Web Designer
 
Albert Pintoy - A Distinguished Software Engineer
Albert Pintoy - A Distinguished Software EngineerAlbert Pintoy - A Distinguished Software Engineer
Albert Pintoy - A Distinguished Software Engineer
Albert Pintoy
 
How to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryErrorHow to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryError
Tier1 app
 
How to Create a Crypto Wallet Like Trust.pptx
How to Create a Crypto Wallet Like Trust.pptxHow to Create a Crypto Wallet Like Trust.pptx
How to Create a Crypto Wallet Like Trust.pptx
riyageorge2024
 
Catching Wire; An introduction to CBWire 4
Catching Wire; An introduction to CBWire 4Catching Wire; An introduction to CBWire 4
Catching Wire; An introduction to CBWire 4
Ortus Solutions, Corp
 
Shift Right Security for EKS Webinar Slides
Shift Right Security for EKS Webinar SlidesShift Right Security for EKS Webinar Slides
Shift Right Security for EKS Webinar Slides
Anchore
 
Quasar Framework Introduction for C++ develpoers
Quasar Framework Introduction for C++ develpoersQuasar Framework Introduction for C++ develpoers
Quasar Framework Introduction for C++ develpoers
sadadkhah
 
Best HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRMBest HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRM
accordHRM
 
Multi-Agent Era will Define the Future of Software
Multi-Agent Era will Define the Future of SoftwareMulti-Agent Era will Define the Future of Software
Multi-Agent Era will Define the Future of Software
Ivo Andreev
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
cram_advancedword2007version2025final.ppt
cram_advancedword2007version2025final.pptcram_advancedword2007version2025final.ppt
cram_advancedword2007version2025final.ppt
ahmedsaadtax2025
 
Bridging Sales & Marketing Gaps with IInfotanks’ Salesforce Account Engagemen...
Bridging Sales & Marketing Gaps with IInfotanks’ Salesforce Account Engagemen...Bridging Sales & Marketing Gaps with IInfotanks’ Salesforce Account Engagemen...
Bridging Sales & Marketing Gaps with IInfotanks’ Salesforce Account Engagemen...
jamesmartin143256
 
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb ClarkDeploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Peter Caitens
 
GC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance EngineeringGC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance Engineering
Tier1 app
 
Grand Theft Auto 6 PC Game Cracked Full Setup Download
Grand Theft Auto 6 PC Game Cracked Full Setup DownloadGrand Theft Auto 6 PC Game Cracked Full Setup Download
Grand Theft Auto 6 PC Game Cracked Full Setup Download
Iobit Uninstaller Pro Crack
 

Lambda Expressions in C++

  • 1. [](){}(); Or How I Learned To Stop Worrying and Love the Lambda Pat Viafore HSV.cpp Meetup 3/15/2017
  • 3. Lambda Expressions Lambda Calculus Church-Turing Thesis Conversion and Reduction Complicated Mathematics Functional Programming Underpinnings of Computer Science Lisp?
  • 9. void print(std::function<bool()> func) { std::string str = func() ? "true" : "false"; std::cout << str << “n”; } auto isFiveGreaterThanThree = [](){ return 5 > 3; }; print(isFiveGreaterThanThree);
  • 11. void print(int param, std::function<bool(int)> func) { std::string str = func(param) ? "true" : "false"; std::cout << str << “n”; } auto isGreaterThanThree = [](int num){ return num > 3; }; print(5, isGreaterThanThree);
  • 13. void print(int num, std::function<bool(int)> func) { std::string str = func(num) ? "true" : "false"; std::cout << str << “n”; } int target = 3; auto isGreaterThan = [target](int n){ return n > target; }; target = 6; print(5, isGreaterThan);
  • 14. Capture List By Value By Reference [this] [a,b] [=] [&a,&b] [&] Prefer Explicit Captures Over Default Captures
  • 15. class A { public: int x; A(): x(10) {} std::function<bool()> getLambda() { return [=](){ return x+2; }; } }; int main() { A* a = new A(); auto lambda = a->getLambda(); delete a; lambda(); } This is implicitly this->x. The this parameter is what gets captured, not x.
  • 16. class A { public: int x; A(): x(10) {} std::function<bool()> getLambda() { return [copy=x](){ return copy+2; }; } }; int main() { A* a = new A(); auto lambda = a->getLambda(); delete a; lambda(); } C++14 gives us init captures, where we can initialize the variables we capture (useful for any non-local captures)
  • 17. Why? Dependency Injection Pass a function to inject a dependency Functional Programming Styles Mapping and Filtering just got a whole lot easier Algorithm Library auto isSpecial = [](MacAddress& mac){ return MacAddress::ItuAddress == mac; }; any_of(macs.begin(), macs.end(), isSpecial); count_if(macs.begin(), macs.end(), isSpecial); replace_if(macs.begin(), macs.end(), isSpecial, MacAddress::BlankMacAddress); sort(ips.begin(), ips.end(), [](IpAddressV4& ip1, IpAddressV4& ip2) { return ip1.getNetworkByteOrder() < ip2.getNetworkByteOrder()); });
  翻译: