-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathG22_Example_2.cpp
More file actions
41 lines (32 loc) · 1.04 KB
/
G22_Example_2.cpp
File metadata and controls
41 lines (32 loc) · 1.04 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
/**************************************************************************************************
*
* \file G22_Example_2.cpp
* \brief Guideline 22: Prefer Value Semantics to Reference Semantics
*
* Copyright (C) 2022 Klaus Iglberger - All Rights Reserved
*
* This file is part of the supplemental material for the O'Reilly book "C++ Software Design"
* (https://www.oreilly.com/library/view/c-software-design/9781098113155/).
*
**************************************************************************************************/
#include <cstdlib>
#include <iostream>
#include <span>
#include <vector>
#include <algorithm>
void print( std::span<int> s )
{
std::cout << " (";
for( int i : s ) {
std::cout << ' ' << i;
}
std::cout << " )\n";
}
int main()
{
std::vector<int> vec{ 1, -3, 27, 42, 4, -8, 22, 42, 37, 4, 18, 9 };
auto const pos = std::max_element( begin(vec), end(vec) );
vec.erase( std::remove( begin(vec), end(vec), *pos ), end(vec) );
print( vec );
return EXIT_SUCCESS;
}