-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA14-7-2.cpp
More file actions
84 lines (50 loc) · 1.18 KB
/
A14-7-2.cpp
File metadata and controls
84 lines (50 loc) · 1.18 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
// Rule: A14-7-2
// Source line: 21096
// Original file: A14-7-2.cpp
// $Id: A14-7-2.cpp 312645 2018-03-21 11:44:35Z michal.szczepankiewicz $
#include <cstdint>
//in A.hpp
#include <functional>
struct A
{
std::uint8_t x;
};
namespace std {
//compliant, case (2)
//template specialization for the user-defined type
//in the same file as the type declaration
template<>
struct hash<A>
{
size_t operator()(const A& a) const noexcept
{
return std::hash<decltype(a.x)>()(a.x);
}
};
}
//traits.hpp
#include <type_traits>
#include <cstdint>
template<typename T>
struct is_serializable : std::false_type {};
//compliant, case (1)
template<>
struct is_serializable<std::uint8_t> : std::true_type {};
//func.cpp
#include <vector>
//non-compliant, not declared
//in the same file as
//is_serializable class
template<>
struct is_serializable<std::uint16_t> : std::true_type {};
template<typename T, typename = std::enable_if<is_serializable<T>::value>>
std::vector<std::uint8_t> serialize(const T& t)
{
//only a basic stub
return std::vector<std::uint8_t>{t};
}
#include <string>
int main()
{
serialize(std::uint8_t{3});
}