-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.cpp
36 lines (30 loc) · 888 Bytes
/
example.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
#include "strong-types.hpp"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
struct NaturalInt : strong_type<unsigned int, NaturalInt> {};
struct Name : public strong_type<std::string, Name> {};
int main()
{
// Use unsigned numbers safely
NaturalInt a{5};
std::vector<NaturalInt> numbers = {{1}, {56}, {90}, {56}, {2}, {78}, {5}};
for(auto each : numbers) {
std::cout << each << ' ';
}
std::cout << '\n';
std::sort(numbers.begin(), numbers.end());
for(auto each : numbers) {
std::cout << each << ' ';
}
std::cout << '\n';
// Create strong string typedefs
Name person{{"Jean"}};
Name person2{{"Jeff"}};
person += "-Paul";
std::cout << person << '\n';
std::cout << (person < person2) << '\n';
std::cout << "Using v member directly: " << person.v << '\n';
return 0;
}