SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
INLINE FUNCTION
The lambda function declaration type and Inline
NORMAL FUNCTION
 Function definition is above main()
 Function is called inside main()
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void assign(int& v){
static int n = 1; v = n++;
}
void print(int v){
cout << v << " ";
}
int main(){
vector<int> vec(10);
for_each(vec.begin(), vec.end(), print);
for_each(vec.begin(), vec.end(), assign);
for_each(vec.begin(), vec.end(), print);
return 0;
}
Assign
Print
LAMBDA FUNCTIONS
 C++11 provides the ability to create anonymous functions, called lambda
functions.
 It allows a function to be defined at the point where it's needed in another
expression.
 It is a function that we can write inline in our code in order to pass in to another
function.
LAMBDA DECLARATION AND CALLS
Assign
Print
Print
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
vector<int> vec(10);
for_each(vec.begin(), vec.end(), [ ](int v){cout << v << " “;});
for_each(vec.begin(), vec.end(), [ ](int& v){ static int n = 1; v = n++;});
for_each(vec.begin(), vec.end(), [ ](int v){cout << v << " “;});
return 0;
}
MORE ABOUT LAMBDA
 It is a function creation inside another function
 Output = function (input, input, [ ](output){definition});
 This call causes to runtime create variables
 It is not available in < g++11 versions so for that we use another procedure called
inline
INLINE FUNCTION
Write inline with the function name before the output type
InlineType Name (inputs..)
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
Inline void assign(int& v){
static int n = 1; v = n++;
}
Inline void print(int v){
cout << v << " ";
}
int main(){
vector<int> vec(10);
for_each(vec.begin(), vec.end(), print);
for_each(vec.begin(), vec.end(), assign);
for_each(vec.begin(), vec.end(), print);
return 0;
}
Assign
Print
Print
MORE ABOUT INLINE
Inline functions are the functions which on call by the compiler are copied to the
set. Where ever the function call is found it is replaced by its code. Inline
functions are declared by adding Inline keyword in front of the name. Rest they
have same defining pattern as normal function.
INLINEVS LAMBDA NOTATION FUNCTION
(INLINE IS NOT A REPLACEMENT OF LAMBDA DECLARATION)
 Lambda functions, as they are called, are a way of creating a object that
represents a function.
 The object is then commonly passed to other functions to control how the other
functions work.
 Take a look at sort() or transform() from the standard library to see what I mean.
(There's some templates involved to make this work in C++, but that's outside the
scope of this answer.)
 Inline function is always available for call whereas Lambda is gone with
the call.
 Thus, these two things are pretty much unrelated to each other.They're not
substitutes of each other in any way at all.

More Related Content

PPTX
SQLite database in android
PPTX
Core java
PPT
SQLITE Android
PPTX
android sqlite
PPSX
Java String class
PPTX
C# Arrays
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
PPTX
Lexical analyzer generator lex
SQLite database in android
Core java
SQLITE Android
android sqlite
Java String class
C# Arrays
Basic Concepts of OOPs (Object Oriented Programming in Java)
Lexical analyzer generator lex

What's hot (20)

PPTX
Applets in java
PPTX
Android Intent.pptx
PPT
Input output streams
PPT
Java Basics
PPT
Java Notes
PPT
C# Exceptions Handling
PPTX
Object Oriented Programming Concepts
PDF
Applications Android - cours 7 : Ressources et adaptation au matériel
PPT
Core java concepts
PDF
PPT
Core java slides
PPT
Linux architecture
PDF
String handling(string class)
PPT
Design patterns ppt
PDF
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
PPTX
Multithreading in java
PPTX
Les Streams de Java 8
PPS
Java Exception handling
PPTX
Notification android
PPTX
Virtual function in C++ Pure Virtual Function
Applets in java
Android Intent.pptx
Input output streams
Java Basics
Java Notes
C# Exceptions Handling
Object Oriented Programming Concepts
Applications Android - cours 7 : Ressources et adaptation au matériel
Core java concepts
Core java slides
Linux architecture
String handling(string class)
Design patterns ppt
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Multithreading in java
Les Streams de Java 8
Java Exception handling
Notification android
Virtual function in C++ Pure Virtual Function
Ad

Similar to Inline and lambda function (20)

PPTX
Microsoft 2014 Dev Plataform - Roslyn -& ASP.NET vNext
PPTX
Function in c program
PPTX
Fundamentals of functions in C program.pptx
DOCX
PPTX
Function C++
DOCX
Functions.docx
PPTX
Fundamental of programming Fundamental of programming
PPTX
Blazing Fast Windows 8 Apps using Visual C++
PPTX
Kotlin as a Better Java
PPT
Fp201 unit5 1
PPT
Functions and pointers_unit_4
PPTX
Functions
PPTX
Python Lecture 4
PDF
Python_Functions.pdf
PDF
[ITP - Lecture 12] Functions in C/C++
PPTX
Function in C program
PPTX
C function
PPT
User Defined Functions
PPT
Practical basics on c++
Microsoft 2014 Dev Plataform - Roslyn -& ASP.NET vNext
Function in c program
Fundamentals of functions in C program.pptx
Function C++
Functions.docx
Fundamental of programming Fundamental of programming
Blazing Fast Windows 8 Apps using Visual C++
Kotlin as a Better Java
Fp201 unit5 1
Functions and pointers_unit_4
Functions
Python Lecture 4
Python_Functions.pdf
[ITP - Lecture 12] Functions in C/C++
Function in C program
C function
User Defined Functions
Practical basics on c++
Ad

More from Jawad Khan (20)

PPTX
2.1 input and output in c
PPTX
2.2 variable arithmetics and logics
PPTX
1.2 programming fundamentals
PPTX
1.1 programming fundamentals
PPTX
7 8. emi - analog instruments and digital instruments
PPTX
6. emi instrument transformers (with marking)
PPTX
5 emi ac bridges (with marking)
PPTX
4. emi potentiometer and ac bridges
PPTX
3 .emi wattmeter and energy meter
PPTX
2. emi analog electromechanical instruments
PPTX
1. emi concept of measurement system
PPTX
Varibale frequency response lecturer 2 - audio+
PPTX
Variable frequency response lecture 3 - audio
PPTX
Varibale frequency response lecturer 1 - audio
PPTX
Two port network - part 3
PPTX
Two port network - part 2
PPTX
Two port network - part 1
PPTX
4. ideal transformer and load conversion
PPTX
3. magnetic coupled circuits examples
PPTX
2. magnetic coupled circuits
2.1 input and output in c
2.2 variable arithmetics and logics
1.2 programming fundamentals
1.1 programming fundamentals
7 8. emi - analog instruments and digital instruments
6. emi instrument transformers (with marking)
5 emi ac bridges (with marking)
4. emi potentiometer and ac bridges
3 .emi wattmeter and energy meter
2. emi analog electromechanical instruments
1. emi concept of measurement system
Varibale frequency response lecturer 2 - audio+
Variable frequency response lecture 3 - audio
Varibale frequency response lecturer 1 - audio
Two port network - part 3
Two port network - part 2
Two port network - part 1
4. ideal transformer and load conversion
3. magnetic coupled circuits examples
2. magnetic coupled circuits

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Electronic commerce courselecture one. Pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Approach and Philosophy of On baking technology
PPTX
Cloud computing and distributed systems.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Spectroscopy.pptx food analysis technology
PDF
Machine learning based COVID-19 study performance prediction
PPT
Teaching material agriculture food technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Electronic commerce courselecture one. Pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Advanced methodologies resolving dimensionality complications for autism neur...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Per capita expenditure prediction using model stacking based on satellite ima...
sap open course for s4hana steps from ECC to s4
Chapter 3 Spatial Domain Image Processing.pdf
Understanding_Digital_Forensics_Presentation.pptx
Encapsulation_ Review paper, used for researhc scholars
Approach and Philosophy of On baking technology
Cloud computing and distributed systems.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Programs and apps: productivity, graphics, security and other tools
Spectroscopy.pptx food analysis technology
Machine learning based COVID-19 study performance prediction
Teaching material agriculture food technology
Building Integrated photovoltaic BIPV_UPV.pdf

Inline and lambda function

  • 1. INLINE FUNCTION The lambda function declaration type and Inline
  • 2. NORMAL FUNCTION  Function definition is above main()  Function is called inside main() #include <iostream> #include <algorithm> #include <vector> using namespace std; void assign(int& v){ static int n = 1; v = n++; } void print(int v){ cout << v << " "; } int main(){ vector<int> vec(10); for_each(vec.begin(), vec.end(), print); for_each(vec.begin(), vec.end(), assign); for_each(vec.begin(), vec.end(), print); return 0; } Assign Print
  • 3. LAMBDA FUNCTIONS  C++11 provides the ability to create anonymous functions, called lambda functions.  It allows a function to be defined at the point where it's needed in another expression.  It is a function that we can write inline in our code in order to pass in to another function.
  • 4. LAMBDA DECLARATION AND CALLS Assign Print Print #include <iostream> #include <algorithm> #include <vector> using namespace std; int main(){ vector<int> vec(10); for_each(vec.begin(), vec.end(), [ ](int v){cout << v << " “;}); for_each(vec.begin(), vec.end(), [ ](int& v){ static int n = 1; v = n++;}); for_each(vec.begin(), vec.end(), [ ](int v){cout << v << " “;}); return 0; }
  • 5. MORE ABOUT LAMBDA  It is a function creation inside another function  Output = function (input, input, [ ](output){definition});  This call causes to runtime create variables  It is not available in < g++11 versions so for that we use another procedure called inline
  • 6. INLINE FUNCTION Write inline with the function name before the output type InlineType Name (inputs..) #include <iostream> #include <algorithm> #include <vector> using namespace std; Inline void assign(int& v){ static int n = 1; v = n++; } Inline void print(int v){ cout << v << " "; } int main(){ vector<int> vec(10); for_each(vec.begin(), vec.end(), print); for_each(vec.begin(), vec.end(), assign); for_each(vec.begin(), vec.end(), print); return 0; } Assign Print Print
  • 7. MORE ABOUT INLINE Inline functions are the functions which on call by the compiler are copied to the set. Where ever the function call is found it is replaced by its code. Inline functions are declared by adding Inline keyword in front of the name. Rest they have same defining pattern as normal function.
  • 8. INLINEVS LAMBDA NOTATION FUNCTION (INLINE IS NOT A REPLACEMENT OF LAMBDA DECLARATION)  Lambda functions, as they are called, are a way of creating a object that represents a function.  The object is then commonly passed to other functions to control how the other functions work.  Take a look at sort() or transform() from the standard library to see what I mean. (There's some templates involved to make this work in C++, but that's outside the scope of this answer.)  Inline function is always available for call whereas Lambda is gone with the call.  Thus, these two things are pretty much unrelated to each other.They're not substitutes of each other in any way at all.

Editor's Notes

  • #7: // simple memory: Output Size: 1.8488130569458 MiB (0.01s less) //inline memory: Output Size: 1.84916877746582 MiB (+300bits more)