diff --git a/doc/technical/howto/HashFunctions.txt b/doc/technical/howto/HashFunctions.txt index 07e353195..1ca92d87d 100644 --- a/doc/technical/howto/HashFunctions.txt +++ b/doc/technical/howto/HashFunctions.txt @@ -65,7 +65,6 @@ at the code [source,C] ---- template struct hash - : std::unary_function { std::size_t operator()(T const& val) const { @@ -78,7 +77,15 @@ with the name +hash_value(val)+ -- when instantiating this template for your cus class or type, the compiler will search this function not only in the current scope, but also in the namespace defining your custom type +T+ (this mechanism is known as ``**A**rgument **D**ependant **L**ookup''). Meaning that all we'd need to do is to define a -free function or friend function named +hash_value+ alongside with our custom data types (classes). +free function or friend function named +hash_value+ alongside with our custom data types +(classes).footnote:[Before C++11, such _functor objects_ were typically derived from +`std::unary_function`, which provided typedefs `argument_type` and `result_type` -- +these were actually picked up to be able to handle such generic function-like objects. +Such is no longer needed and deprecated with C++17, since library code today either +relies on _traits templates_ to query for some feature like a function operator, +and contemporary code even relies on _concepts_ to express such a requirement +from the code depending on it. Today it is sufficient just to expose an +accessible function call operator.] To further facilitate providing custom hash functions, boost defines a function +boost::hash_combine(size_t seed, size_t hashValue)+, allowing to _chain up_ the diff --git a/src/lib/hash-indexed.hpp b/src/lib/hash-indexed.hpp index 34a7983d7..916c51fef 100644 --- a/src/lib/hash-indexed.hpp +++ b/src/lib/hash-indexed.hpp @@ -53,8 +53,6 @@ extern "C" { #include "lib/luid.h" } -#include - namespace lib { @@ -149,14 +147,12 @@ namespace lib { /** enables use of BA objects as keys within std::unordered_map */ struct UseEmbeddedHash - : public std::unary_function { HashVal operator() (BA const& obj) const { return obj.getID(); } }; /** trivial hash functor using the ID as hash */ struct UseHashID - : public std::unary_function { HashVal operator() (ID const& id) const { return id; } }; diff --git a/src/lib/idi/entry-id.hpp b/src/lib/idi/entry-id.hpp index 172f16fb1..e5e1f51c8 100644 --- a/src/lib/idi/entry-id.hpp +++ b/src/lib/idi/entry-id.hpp @@ -183,7 +183,6 @@ namespace idi { /** using BareEntryID derived objects as keys within std::unordered_map */ struct UseEmbeddedHash - : public std::unary_function { size_t operator() (BareEntryID const& obj) const { return obj.getHash(); } }; diff --git a/src/lib/util.cpp b/src/lib/util.cpp index 0065fc8f7..d9a4fa1cb 100644 --- a/src/lib/util.cpp +++ b/src/lib/util.cpp @@ -26,7 +26,6 @@ #include #include -#include // we need operator! for bind-expressions using boost::algorithm::trim_right_copy_if; using boost::algorithm::is_any_of; @@ -38,14 +37,16 @@ using boost::algorithm::is_space; using std::regex; using std::regex_match; +using std::string; using std::function; using util::_Fmt; namespace util { - using ChPredicate = function; - ChPredicate operator! (ChPredicate p) { return not bind(p,_1); } + using Cha = string::value_type; + using ChPredicate = function; + ChPredicate operator! (ChPredicate p) { return [p](Cha c){ return not p(c); }; } // character classes used for sanitising a string ChPredicate isValid (is_alnum() or is_any_of("-_.+$()@")); ///< characters to be retained diff --git a/src/steam/asset/db.hpp b/src/steam/asset/db.hpp index cc632c960..cfdf17fc8 100644 --- a/src/steam/asset/db.hpp +++ b/src/steam/asset/db.hpp @@ -30,7 +30,6 @@ #include #include -// #include /////////TODO which boost include to use here?? #include @@ -70,7 +69,6 @@ namespace asset { * already containing valid hash values. */ struct IdentityHash - : public std::unary_function { size_t operator() (size_t val) const { return val; }