Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitedf7ba8

Browse files
committed
std::hash for actor_ref
1 parent522fb58 commitedf7ba8

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

‎lib/acto.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ inline void sleep(const D duration) {
182182
* Reference to an actor object.
183183
*/
184184
classactor_ref {
185+
friendclassstd::hash<actor_ref>;
185186
friendvoidjoin(actor_ref& obj);
186187
friendvoiddestroy(actor_ref& object);
187188

@@ -480,3 +481,11 @@ spawn(actor_ref context, const actor_thread thread_opt, P&&... p) {
480481
}
481482

482483
}// namespace acto
484+
485+
template<>
486+
classstd::hash<acto::actor_ref> {
487+
public:
488+
size_toperator()(const acto::actor_ref& ref)constnoexcept {
489+
returnreinterpret_cast<size_t>(ref.m_object);
490+
}
491+
};

‎test/tests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include"catch.hpp"
33

44
#include<iostream>
5+
#include<map>
6+
#include<unordered_map>
57
#include<vector>
68

79
TEST_CASE("Finalize library") {
@@ -88,3 +90,19 @@ TEST_CASE("Process binded actors at exit") {
8890
// The sent message should be processed at thread exit.
8991
REQUIRE(*counter ==1);
9092
}
93+
94+
TEST_CASE("Key for containers") {
95+
structA : acto::actor { };
96+
97+
std::map<acto::actor_ref,int> map;
98+
std::unordered_map<acto::actor_ref,int> hash_map;
99+
auto a = acto::spawn<A>();
100+
101+
map.emplace(a,1);
102+
hash_map.emplace(a,2);
103+
104+
CHECK(map.find(a) == map.begin());
105+
CHECK(hash_map.find(a) == hash_map.begin());
106+
107+
acto::destroy(a);
108+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp