diff --git a/.clang-tidy b/.clang-tidy index 44cc1538e9aa9..54c2b0183dbbe 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -23,7 +23,6 @@ readability-*,\ -bugprone-undefined-memory-manipulation,\ -bugprone-unused-return-value,\ -bugprone-use-after-move,\ --cert-dcl58-cpp,\ -cert-dcl59-cpp,\ -cert-env33-c,\ -cert-err34-c,\ diff --git a/src/effect.cpp b/src/effect.cpp index d0fa7c5da952b..893f9a3a4ba91 100644 --- a/src/effect.cpp +++ b/src/effect.cpp @@ -176,9 +176,11 @@ void weed_msg( player &p ) } } -static void extract_effect( JsonObject &j, - std::unordered_map, double> &data, - const std::string &mod_type, std::string data_key, std::string type_key, std::string arg_key ) +static void extract_effect( + JsonObject &j, + std::unordered_map, double, + cata::tuple_hash> &data, + const std::string &mod_type, std::string data_key, std::string type_key, std::string arg_key ) { double val = 0; double reduced_val = 0; diff --git a/src/effect.h b/src/effect.h index c4ab5110ba5aa..cba6aa4620764 100644 --- a/src/effect.h +++ b/src/effect.h @@ -131,7 +131,9 @@ class effect_type std::string remove_memorial_log; /** Key tuple order is:("base_mods"/"scaling_mods", reduced: bool, type of mod: "STR", desired argument: "tick") */ - std::unordered_map, double> mod_data; + std::unordered_map < + std::tuple, double, cata::tuple_hash + > mod_data; }; class effect diff --git a/src/mutation.h b/src/mutation.h index 2bdb829acaa4c..a62a0a96a91d5 100644 --- a/src/mutation.h +++ b/src/mutation.h @@ -212,8 +212,9 @@ struct mutation_branch { std::map encumbrance_covered; // Body parts that now need OVERSIZE gear std::set restricts_gear; + // Mutation stat mods /** Key pair is */ - std::unordered_map, int> mods; // Mutation stat mods + std::unordered_map, int, cata::tuple_hash> mods; std::map armor; std::vector initial_ma_styles; // Martial art styles that can be chosen upon character generation diff --git a/src/mutation_data.cpp b/src/mutation_data.cpp index a88f8e17b44bb..512e8ef51f4d8 100644 --- a/src/mutation_data.cpp +++ b/src/mutation_data.cpp @@ -49,8 +49,9 @@ bool string_id::is_valid() const return trait_groups.count( *this ); } -static void extract_mod( JsonObject &j, std::unordered_map, int> &data, - const std::string &mod_type, bool active, const std::string &type_key ) +static void extract_mod( + JsonObject &j, std::unordered_map, int, cata::tuple_hash> &data, + const std::string &mod_type, bool active, const std::string &type_key ) { int val = j.get_int( mod_type, 0 ); if( val != 0 ) { @@ -58,8 +59,9 @@ static void extract_mod( JsonObject &j, std::unordered_map, int> &mods ) +static void load_mutation_mods( + JsonObject &jsobj, const std::string &member, + std::unordered_map, int, cata::tuple_hash> &mods ) { if( jsobj.has_object( member ) ) { JsonObject j = jsobj.get_object( member ); diff --git a/src/savegame.cpp b/src/savegame.cpp index f44414c9a194e..5e678f7f9fccf 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -1220,14 +1220,14 @@ struct mongroup_hash { std::size_t operator()( const mongroup &mg ) const { // Note: not hashing monsters or position size_t ret = std::hash()( mg.type ); - std::hash_combine( ret, mg.radius ); - std::hash_combine( ret, mg.population ); - std::hash_combine( ret, mg.target ); - std::hash_combine( ret, mg.interest ); - std::hash_combine( ret, mg.dying ); - std::hash_combine( ret, mg.horde ); - std::hash_combine( ret, mg.horde_behaviour ); - std::hash_combine( ret, mg.diffuse ); + cata::hash_combine( ret, mg.radius ); + cata::hash_combine( ret, mg.population ); + cata::hash_combine( ret, mg.target ); + cata::hash_combine( ret, mg.interest ); + cata::hash_combine( ret, mg.dying ); + cata::hash_combine( ret, mg.horde ); + cata::hash_combine( ret, mg.horde_behaviour ); + cata::hash_combine( ret, mg.diffuse ); return ret; } }; diff --git a/src/tuple_hash.h b/src/tuple_hash.h index 3862d1887fd02..0462f4ad330b4 100644 --- a/src/tuple_hash.h +++ b/src/tuple_hash.h @@ -1,12 +1,12 @@ #pragma once -#ifndef TUPLE_HASH_H -#define TUPLE_HASH_H +#ifndef CATA_TUPLE_HASH_H +#define CATA_TUPLE_HASH_H // Support for tuple and pair hashing. // This is taken almost directly from the boost library code. // Function has to live in the std namespace // so that it is picked up by argument-dependent name lookup (ADL). -namespace std +namespace cata { namespace { @@ -20,7 +20,7 @@ namespace template inline void hash_combine( std::size_t &seed, const T &v ) { - seed ^= hash()( v ) + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 ); + seed ^= std::hash()( v ) + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 ); } // Recursive template code derived from Matthieu M. @@ -29,31 +29,27 @@ struct HashValueImpl { static void apply( size_t &seed, const Tuple &tuple ) { HashValueImpl < Tuple, Index - 1 >::apply( seed, tuple ); - hash_combine( seed, get( tuple ) ); + hash_combine( seed, std::get( tuple ) ); } }; template struct HashValueImpl { static void apply( size_t &seed, const Tuple &tuple ) { - hash_combine( seed, get<0>( tuple ) ); + hash_combine( seed, std::get<0>( tuple ) ); } }; } // namespace -template -struct hash> { - size_t - operator()( const std::tuple &tt ) const { +struct tuple_hash { + template + std::size_t operator()( const std::tuple &tt ) const { size_t seed = 0; HashValueImpl >::apply( seed, tt ); return seed; } -}; - -template -struct hash> { + template std::size_t operator()( const std::pair &v ) const { std::size_t seed = 0; hash_combine( seed, v.first ); @@ -61,6 +57,7 @@ struct hash> { return seed; } }; -} // namespace std -#endif +} // namespace cata + +#endif // CATA_TUPLE_HASH_H