Repository navigation
Expand file tree
/
Copy pathPrinter.h
More file actions
99 lines (79 loc) · 2.62 KB
/
Copy pathPrinter.h
File metadata and controls
99 lines (79 loc) · 2.62 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
#pragma once
#include <array>
#include <concepts>
#include <deque>
#include <forward_list>
#include <iostream>
#include <list>
#include <map>
#include <unordered_map>
#include <utility>
#include <vector>
template <typename, template <typename ...> typename>
inline constexpr bool is_specialization = false;
template <template <typename ...> typename T, typename ... ARGS>
inline constexpr bool is_specialization<T<ARGS ...>, T> = true;
template <typename T>
concept isDeque = is_specialization<T, std::deque>;
template <typename T>
concept isForwardList = is_specialization<T, std::forward_list>;
template <typename T>
concept isList = is_specialization<T, std::list>;
template <typename T>
concept isVector = is_specialization<T, std::vector>;
static_assert(isVector<std::vector<int>> and !isList<std::vector<int>>);
static_assert(!isVector<std::list<int>> and isList<std::list<int>>);
template <typename TYPE, template<typename, size_t> typename T, size_t N>
inline constexpr bool is_specialization_array = false;
template <template<typename, size_t> typename T, typename TYPE, size_t N>
inline constexpr bool is_specialization_array<T<TYPE, N>, T, N> = true;
template <typename>
struct array_size;
template <typename T, size_t N>
struct array_size<std::array<T, N>>
{
static const size_t value = N;
};
template <typename T>
concept isArray = is_specialization_array<T, std::array, array_size<T>::value>;
template <typename T>
requires isArray<T> or isDeque<T> or isForwardList<T> or isList<T> or isVector<T>
std::ostream& operator<<(std::ostream& os, T v)
{
os << "[";
if (!v.empty())
{
auto it = v.begin();
os << *it;
for (++it; it != v.end(); ++it)
os << ", " << *it;
}
return os << "]";
}
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> p)
{
return os << "{" << p.first << ", " << p.second << "}";
}
template<typename T>
concept isMap = is_specialization<T, std::map>;
template<typename T>
concept isMultiMap = is_specialization<T, std::multimap>;
template<typename T>
concept isUnorderedMap = is_specialization<T, std::unordered_map>;
template<typename T>
concept isUnorderedMultiMap = is_specialization<T, std::unordered_multimap>;
template <typename T>
requires isMap<T> or isMultiMap<T> or isUnorderedMap<T> or isUnorderedMultiMap<T>
std::ostream& operator<<(std::ostream& os, T map)
{
os << "{";
if (!map.empty())
{
auto it = map.begin();
os << it->first << ": " << it->second;
for (++it; it != map.end(); ++it)
os << ", " << it->first << ": " << it->second;
}
return os << "}";
}