-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchapter_29_concurrency.cpp
More file actions
101 lines (76 loc) · 2.71 KB
/
chapter_29_concurrency.cpp
File metadata and controls
101 lines (76 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*=============================================================================
* CHAPTER 29: CONCURRENCY
* =============================================================================
*
* C++ Development Course - Consolidated Examples
* Original Author: Faranak Rajabi
*
* This file contains 5 code example(s) from Chapter 29.
*
* USAGE:
* - Review each example section
* - Uncomment the code you want to test
* - Compile: g++ -std=c++17 -Wall thisfile.cpp -o program
* - Run: ./program
*
* NOTE:
* Some examples are code snippets designed to illustrate specific
* concepts and may need additional context to compile.
*
=============================================================================*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
// ============================================================================
// EXAMPLE 1: Using primary template
// ============================================================================
int main () {
// Using primary template
std :: cout << isEqual (42 , 42) << ’\ n ’;
std :: cout << isEqual (3.14 , 3.14) << ’\ n ’;
// ============================================================================
// EXAMPLE 2: Class: Widget
// ============================================================================
/*
class Widget {
public :
Widget () {
std :: cout << " Widget default constructor \ n " ;
}
*/
// ============================================================================
// EXAMPLE 3: Code Example
// ============================================================================
/*
Widget ( bool enabled ) : enabled ( enabled ) {
std :: cout << " Widget parameterized constructor \ n " ;
}
*/
// ============================================================================
// EXAMPLE 4: Code Example
// ============================================================================
/*
for ( int i = 0; i < 2; ++ i ) {
animals [ i ] - > makeSound () ; // Calls correct version !
}
*/
// ============================================================================
// EXAMPLE 5: Polymorphic behavior
// ============================================================================
/*
// Polymorphic behavior
for ( const auto & animal : animals2 ) {
animal - > makeSound () ; // Calls correct version
}
// Automatic cleanup with smart pointers !
*/
// ============================================================================
// MAIN FUNCTION
// ============================================================================
// Uncomment the examples above and add your test code here
int main() {
std::cout << "Chapter 29: Concurrency" << std::endl;
// Your test code here
return 0;
}