Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
202 lines (169 loc) · 3.83 KB

File metadata and controls

202 lines (169 loc) · 3.83 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// SampleDebugee.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <memory>
using namespace std;
template <class T>
inline void hash_combine(size_t& seed, const T& v)
{
hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
class Person
{
string firstName_;
string lastName_;
public:
Person(string firstName, string lastName)
: firstName_(firstName)
, lastName_(lastName){}
Person(Person&& other)
: firstName_(std::move(other.firstName_)),
lastName_(std::move(other.lastName_))
{
}
Person& operator=(Person&& other)
{
if (this == &other)
return *this;
firstName_ = std::move(other.firstName_);
lastName_ = std::move(other.lastName_);
return *this;
}
Person(const Person& other) = delete;
Person& operator=(const Person& other) = delete;
friend size_t hash_value(const Person& obj)
{
size_t seed = 0x25CAED3F;
hash_combine(seed, obj.firstName_);
hash_combine(seed, obj.lastName_);
return seed;
}
friend void swap(Person& lhs, Person& rhs)
{
using std::swap;
swap(lhs.firstName_, rhs.firstName_);
swap(lhs.lastName_, rhs.lastName_);
}
friend std::ostream& operator<<(std::ostream& os, const Person& obj)
{
return os
<< obj.firstName_
<< " " << obj.lastName_;
}
friend bool operator==(const Person& lhs, const Person& rhs)
{
return lhs.firstName_ == rhs.firstName_
&& lhs.lastName_ == rhs.lastName_;
}
friend bool operator!=(const Person& lhs, const Person& rhs)
{
return !(lhs == rhs);
}
friend bool lessFirstNameLastName(const Person& lhs, const Person& rhs)
{
if (lhs.firstName_ < rhs.firstName_)
return true;
if (rhs.firstName_ < lhs.firstName_)
return false;
return lhs.lastName_ < rhs.lastName_;
}
friend bool lessLastNameFirstName(const Person& lhs, const Person& rhs)
{
if (lhs.lastName_ < rhs.lastName_)
return true;
if (rhs.lastName_ < lhs.lastName_)
return false;
return lhs.firstName_ < rhs.firstName_;
}
};
class Conference
{
string name_;
string venue_;
public:
Conference(string name, string venue)
: name_(name)
, venue_(venue){}
friend size_t hash_value(const Conference& obj)
{
size_t seed = 0x74058D25;
hash_combine(seed, obj.name_);
hash_combine(seed, obj.venue_);
return seed;
}
};
namespace std
{
template<>
struct hash<Person>
{
size_t operator()(const Person& _Keyval) const
{ // hash _Keyval to size_t value by pseudorandomizing transform
return (hash_value(_Keyval));
}
};
template<>
struct hash<Conference>
{
size_t operator()(const Conference& _Keyval) const
{ // hash _Keyval to size_t value by pseudorandomizing transform
return (hash_value(_Keyval));
}
};
}
class ConverenceAttendees
{
unordered_multimap<Conference const*, shared_ptr<Person>> attendees_;
public:
auto addAttendee(Conference const&conference, shared_ptr<Person>& attendee)
{
attendees_.insert({ &conference,attendee });
return;
}
};
auto printPerson(Person const& person, std::ostream& os)
{
os << person;
return;
}
long add(int a, int b)
{
auto res = long(a);
res += b;
return res;
}
void doAddition(ostream& s)
{
int a = 10;
int b = 20;
auto res = add(a, b);
a =+ 1000;
res = add(res, a);
s << res << endl;
}
int main()
{
Conference PSConfEU("PSConfEU", "Hannover");
auto speaker = make_shared<Person>("Staffan", "Gustafsson");
auto hangAround = make_shared<Person>("Jeffrey", "Snover");
auto organizer = make_shared<Person>("Tobias", "Weltner");
printPerson(*speaker, cout);
vector<shared_ptr<Person>> people;
people.push_back(speaker);
people.push_back(hangAround);
people.push_back(organizer);
ConverenceAttendees ca;
for(auto& p : people)
{
ca.addAttendee(PSConfEU, p);
}
doAddition(cout);
return 0;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.