Skip to content

Commit 1773400

Browse files
committed
events_handler nodiscard fixed, hash changed
1 parent 5de846d commit 1773400

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

include/events/mstd/event_handler.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ namespace mstd {
3232
#else
3333
template<class F, std::enable_if_t<mstd::is_same_function_v<F, event_action_type>, bool> = true>
3434
#endif
35-
[[nodiscard]] constexpr id_type add_callback(const F& callback) {
35+
constexpr id_type add_callback(const F& callback) {
3636
id_type id = _ids.get_next_id();
3737
if (id == id_manager_type::bad_id()) return id;
3838

3939
_events[id] = callback;
4040
return id;
4141
}
4242

43-
[[nodiscard]] constexpr bool remove_callback(const id_type& callbackId) {
43+
constexpr bool remove_callback(const id_type& callbackId) {
4444
auto itr = _events.find(callbackId);
4545
if (itr == _events.end()) {
4646
return false;
@@ -66,11 +66,11 @@ namespace mstd {
6666
#else
6767
template<class F, std::enable_if_t<mstd::is_same_function_v<F, event_action_type>, bool> = true>
6868
#endif
69-
[[nodiscard]] constexpr id_type operator+=(const F& callback) {
69+
constexpr id_type operator+=(const F& callback) {
7070
return add_callback(callback);
7171
}
7272

73-
[[nodiscard]] constexpr bool operator-=(id_type callbackId) {
73+
constexpr bool operator-=(id_type callbackId) {
7474
return remove_callback(callbackId);
7575
}
7676

include/utils/mstd/hash.hpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@
1111
#include "utils_libs.hpp"
1212

1313
namespace mstd {
14-
template<class T>
15-
void hash_combine(size_t& seed, const T& value) {
16-
seed ^= std::hash<T>()(value) + 0x9e3779b9
17-
+ (seed << 6) + (seed >> 2);
14+
template<class T, class... Ts>
15+
void hash_append(size_t& hash_value, const T& value, const Ts&... values) {
16+
hash_value ^= std::hash<T>()(value) + 0x9e3779b9 + (hash_value << 6) + (hash_value >> 2);
17+
18+
if constexpr (sizeof...(Ts) != 0) {
19+
hash_append(hash_value, values...);
20+
}
1821
}
1922

20-
template<class... Ts>
21-
void hash_combine(size_t& seed, const Ts&... values) {
22-
(hash_combine(seed, values), ...);
23+
template<class T0, class T1, class... Ts>
24+
size_t hash_combine(const T0& value0, const T1& value1, const Ts&... values) {
25+
size_t hash_value = 0;
26+
hash_append(hash_value, value0, value1, values...);
27+
return hash_value;
2328
}
2429

2530
template<class Iter>
26-
void hash_combine(size_t& seed, const Iter& begin, const Iter& end) {
27-
for (const Iter& i = begin; i != end; ++i) {
28-
hash_combine(seed, *i);
31+
void hash_range(size_t& seed, const Iter& begin, const Iter& end) {
32+
for (Iter i = begin; i != end; ++i) {
33+
hash_append(seed, *i);
2934
}
3035
}
3136
}

0 commit comments

Comments
 (0)