Skip to content

Commit 505ed83

Browse files
committed
Function object (Functors) in C++ STL
1 parent 14991ce commit 505ed83

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

Functors.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//! Function object (Functors) in STL
2+
3+
#include<iostream>
4+
#include<functional>
5+
#include<algorithm>
6+
7+
using namespace std;
8+
int main(){
9+
int arrays[] = {70, 40, 90, 45, 23, 1, 2};
10+
int n = sizeof(arrays) / sizeof(arrays[0]);
11+
sort(arrays, arrays + 5); // assending order
12+
sort(arrays, arrays + 7, greater<int>()); // dessending order
13+
for (int i = 0; i < n; i++)
14+
{
15+
cout << "The array is: " << arrays[i] << endl;
16+
}
17+
18+
return 0;
19+
}
20+
21+
22+
//? Function Object : Function wrapped in a class so that it available like an object

Functors.exe

70.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)