Upgrade: address warnings -- obsoleted features
Some pre C++11 features are marked deprecated and will be rejected with C++20 Notably the old marker inferfaces for unary (and binary) functions are no longer needed, since function-like objects can be detected by traits or concepts nowadays Moreover we can get rid of some boost(bind) usages and use a λ
This commit is contained in:
parent
92c99e5b7d
commit
6c627d83dc
5 changed files with 13 additions and 12 deletions
|
|
@ -65,7 +65,6 @@ at the code
|
||||||
[source,C]
|
[source,C]
|
||||||
----
|
----
|
||||||
template <class T> struct hash
|
template <class T> struct hash
|
||||||
: std::unary_function<T, std::size_t>
|
|
||||||
{
|
{
|
||||||
std::size_t operator()(T const& val) const
|
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,
|
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
|
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
|
``**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
|
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
|
+boost::hash_combine(size_t seed, size_t hashValue)+, allowing to _chain up_ the
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,6 @@ extern "C" {
|
||||||
#include "lib/luid.h"
|
#include "lib/luid.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
|
|
||||||
namespace lib {
|
namespace lib {
|
||||||
|
|
||||||
|
|
@ -149,14 +147,12 @@ namespace lib {
|
||||||
|
|
||||||
/** enables use of BA objects as keys within std::unordered_map */
|
/** enables use of BA objects as keys within std::unordered_map */
|
||||||
struct UseEmbeddedHash
|
struct UseEmbeddedHash
|
||||||
: public std::unary_function<BA, HashVal>
|
|
||||||
{
|
{
|
||||||
HashVal operator() (BA const& obj) const { return obj.getID(); }
|
HashVal operator() (BA const& obj) const { return obj.getID(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
/** trivial hash functor using the ID as hash */
|
/** trivial hash functor using the ID as hash */
|
||||||
struct UseHashID
|
struct UseHashID
|
||||||
: public std::unary_function<ID, HashVal>
|
|
||||||
{
|
{
|
||||||
HashVal operator() (ID const& id) const { return id; }
|
HashVal operator() (ID const& id) const { return id; }
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,6 @@ namespace idi {
|
||||||
|
|
||||||
/** using BareEntryID derived objects as keys within std::unordered_map */
|
/** using BareEntryID derived objects as keys within std::unordered_map */
|
||||||
struct UseEmbeddedHash
|
struct UseEmbeddedHash
|
||||||
: public std::unary_function<BareEntryID, size_t>
|
|
||||||
{
|
{
|
||||||
size_t operator() (BareEntryID const& obj) const { return obj.getHash(); }
|
size_t operator() (BareEntryID const& obj) const { return obj.getHash(); }
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <boost/bind.hpp> // we need operator! for bind-expressions
|
|
||||||
|
|
||||||
using boost::algorithm::trim_right_copy_if;
|
using boost::algorithm::trim_right_copy_if;
|
||||||
using boost::algorithm::is_any_of;
|
using boost::algorithm::is_any_of;
|
||||||
|
|
@ -38,14 +37,16 @@ using boost::algorithm::is_space;
|
||||||
using std::regex;
|
using std::regex;
|
||||||
using std::regex_match;
|
using std::regex_match;
|
||||||
|
|
||||||
|
using std::string;
|
||||||
using std::function;
|
using std::function;
|
||||||
using util::_Fmt;
|
using util::_Fmt;
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
|
|
||||||
|
|
||||||
using ChPredicate = function<bool(string::value_type)>;
|
using Cha = string::value_type;
|
||||||
ChPredicate operator! (ChPredicate p) { return not bind(p,_1); }
|
using ChPredicate = function<bool(Cha)>;
|
||||||
|
ChPredicate operator! (ChPredicate p) { return [p](Cha c){ return not p(c); }; }
|
||||||
|
|
||||||
// character classes used for sanitising a string
|
// character classes used for sanitising a string
|
||||||
ChPredicate isValid (is_alnum() or is_any_of("-_.+$()@")); ///< characters to be retained
|
ChPredicate isValid (is_alnum() or is_any_of("-_.+$()@")); ///< characters to be retained
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
// #include <boost/functional/hash.hpp> /////////TODO which boost include to use here??
|
|
||||||
#include <boost/utility.hpp>
|
#include <boost/utility.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -70,7 +69,6 @@ namespace asset {
|
||||||
* already containing valid hash values.
|
* already containing valid hash values.
|
||||||
*/
|
*/
|
||||||
struct IdentityHash
|
struct IdentityHash
|
||||||
: public std::unary_function<size_t, size_t>
|
|
||||||
{
|
{
|
||||||
size_t
|
size_t
|
||||||
operator() (size_t val) const { return val; }
|
operator() (size_t val) const { return val; }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue