-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathid.cpp
54 lines (45 loc) · 789 Bytes
/
id.cpp
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
#include "id.h"
#include <cassert>
#include <iostream>
#include <sstream>
int id::sm_next_value{0};
id::id()
: m_value{sm_next_value++}
{
}
id create_new_id() noexcept
{
return id();
}
void test_id()
{
#ifndef NDEBUG
{
const auto a{create_new_id()};
const auto b{create_new_id()};
assert(a == a);
assert(!(a == b));
assert(a != b);
}
// operator<<
{
const id i = create_new_id();
std::stringstream s;
s << i;
assert(!s.str().empty());
}
#endif // NDEBUG
}
bool operator==(const id& lhs, const id& rhs) noexcept
{
return lhs.get() == rhs.get();
}
bool operator!=(const id& lhs, const id& rhs) noexcept
{
return !(lhs == rhs);
}
std::ostream& operator<<(std::ostream& os, const id& i) noexcept
{
os << i.get();
return os;
}