forked from hsutter/cppfront
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpure2-hashable.cpp
More file actions
87 lines (63 loc) · 3.14 KB
/
pure2-hashable.cpp
File metadata and controls
87 lines (63 loc) · 3.14 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
#define CPP2_INCLUDE_STD Yes
//=== Cpp2 type declarations ====================================================
#include "cpp2util.h"
#line 1 "pure2-hashable.cpp2"
class base;
#line 2 "pure2-hashable.cpp2"
#line 5 "pure2-hashable.cpp2"
class mystruct;
//=== Cpp2 type definitions and function declarations ===========================
#line 1 "pure2-hashable.cpp2"
class base {
#line 2 "pure2-hashable.cpp2"
public: cpp2::i32 h;
public: base(auto&& h_)
CPP2_REQUIRES_ (std::is_convertible_v<CPP2_TYPEOF(h_), std::add_const_t<cpp2::i32>&>) ;
public: auto operator=(auto&& h_) -> base&
CPP2_REQUIRES_ (std::is_convertible_v<CPP2_TYPEOF(h_), std::add_const_t<cpp2::i32>&>) ;
public: [[nodiscard]] auto hash() const& -> size_t;
#line 3 "pure2-hashable.cpp2"
};
class mystruct: public base {
public: cpp2::i32 i;
public: std::string j;
public: cpp2::u64 k;
public: mystruct(auto&& i_, auto&& j_, auto&& k_)
CPP2_REQUIRES_ (std::is_convertible_v<CPP2_TYPEOF(i_), std::add_const_t<cpp2::i32>&> && std::is_convertible_v<CPP2_TYPEOF(j_), std::add_const_t<std::string>&> && std::is_convertible_v<CPP2_TYPEOF(k_), std::add_const_t<cpp2::u64>&>) ;
public: [[nodiscard]] auto hash() const& -> size_t;
#line 10 "pure2-hashable.cpp2"
};
auto main() -> int;
//=== Cpp2 function definitions =================================================
#line 1 "pure2-hashable.cpp2"
base::base(auto&& h_)
requires (std::is_convertible_v<CPP2_TYPEOF(h_), std::add_const_t<cpp2::i32>&>)
: h{ CPP2_FORWARD(h_) }{}
auto base::operator=(auto&& h_) -> base&
requires (std::is_convertible_v<CPP2_TYPEOF(h_), std::add_const_t<cpp2::i32>&>) {
h = CPP2_FORWARD(h_);
return *this;}
[[nodiscard]] auto base::hash() const& -> size_t{
size_t ret {0};
cpp2::hash_combine(ret, std::hash<cpp2::i32>()(h));
return ret;
}
mystruct::mystruct(auto&& i_, auto&& j_, auto&& k_)
requires (std::is_convertible_v<CPP2_TYPEOF(i_), std::add_const_t<cpp2::i32>&> && std::is_convertible_v<CPP2_TYPEOF(j_), std::add_const_t<std::string>&> && std::is_convertible_v<CPP2_TYPEOF(k_), std::add_const_t<cpp2::u64>&>)
: base{ (1) }
, i{ CPP2_FORWARD(i_) }
, j{ CPP2_FORWARD(j_) }
, k{ CPP2_FORWARD(k_) }{}
[[nodiscard]] auto mystruct::hash() const& -> size_t{
size_t ret {0};
cpp2::hash_combine(ret, base::hash());
cpp2::hash_combine(ret, std::hash<cpp2::i32>()(i));
cpp2::hash_combine(ret, std::hash<std::string>()(j));
cpp2::hash_combine(ret, std::hash<cpp2::u64>()(k));
return ret;
}
#line 12 "pure2-hashable.cpp2"
auto main() -> int{
mystruct x {2, "three", 4u};
std::cout << CPP2_UFCS(hash)(cpp2::move(x));
}