mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
4aa197dbdb
fa4632c41714dfaa699bacc6a947d72668a4deef test: Move boost/stdlib includes last (MarcoFalke) fa488f131fd4f5bab0d01376c5a5013306f1abcd scripted-diff: Bump copyright headers (MarcoFalke) fac5c373006a9e4bcbb56843bb85f1aca4d87599 scripted-diff: Sort test includes (MarcoFalke) Pull request description: When writing tests, often includes need to be added or removed. Currently the list of includes is not sorted, so developers that write tests and have `clang-format` installed will either have an unrelated change (sorting) included in their commit or they will have to manually undo the sort. This pull preempts both issues by just sorting all includes in one commit. Please be aware that this is **NOT** a change to policy to enforce clang-format or any other developer guideline or process. Developers are free to use whatever tool they want, see also #18651. Edit: Also includes a commit to bump the copyright headers, so that the touched files don't need to be touched again for that. ACKs for top commit: practicalswift: ACK fa4632c41714dfaa699bacc6a947d72668a4deef jonatack: ACK fa4632c41714dfaa, light review and sanity checks with gcc build and clang fuzz build Tree-SHA512: 130a8d073a379ba556b1e64104d37c46b671425c0aef0ed725fd60156a95e8dc83fb6f0b5330b2f8152cf5daaf3983b4aca5e75812598f2626c39fd12b88b180
59 lines
2.5 KiB
C++
59 lines
2.5 KiB
C++
// Copyright (c) 2016-2020 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_INDIRECTMAP_H
|
|
#define BITCOIN_INDIRECTMAP_H
|
|
|
|
#include <map>
|
|
|
|
template <class T>
|
|
struct DereferencingComparator { bool operator()(const T a, const T b) const { return *a < *b; } };
|
|
|
|
/* Map whose keys are pointers, but are compared by their dereferenced values.
|
|
*
|
|
* Differs from a plain std::map<const K*, T, DereferencingComparator<K*> > in
|
|
* that methods that take a key for comparison take a K rather than taking a K*
|
|
* (taking a K* would be confusing, since it's the value rather than the address
|
|
* of the object for comparison that matters due to the dereferencing comparator).
|
|
*
|
|
* Objects pointed to by keys must not be modified in any way that changes the
|
|
* result of DereferencingComparator.
|
|
*/
|
|
template <class K, class T>
|
|
class indirectmap {
|
|
private:
|
|
typedef std::map<const K*, T, DereferencingComparator<const K*> > base;
|
|
base m;
|
|
public:
|
|
typedef typename base::iterator iterator;
|
|
typedef typename base::const_iterator const_iterator;
|
|
typedef typename base::size_type size_type;
|
|
typedef typename base::value_type value_type;
|
|
|
|
// passthrough (pointer interface)
|
|
std::pair<iterator, bool> insert(const value_type& value) { return m.insert(value); }
|
|
|
|
// pass address (value interface)
|
|
iterator find(const K& key) { return m.find(&key); }
|
|
const_iterator find(const K& key) const { return m.find(&key); }
|
|
iterator lower_bound(const K& key) { return m.lower_bound(&key); }
|
|
const_iterator lower_bound(const K& key) const { return m.lower_bound(&key); }
|
|
size_type erase(const K& key) { return m.erase(&key); }
|
|
size_type count(const K& key) const { return m.count(&key); }
|
|
|
|
// passthrough
|
|
bool empty() const { return m.empty(); }
|
|
size_type size() const { return m.size(); }
|
|
size_type max_size() const { return m.max_size(); }
|
|
void clear() { m.clear(); }
|
|
iterator begin() { return m.begin(); }
|
|
iterator end() { return m.end(); }
|
|
const_iterator begin() const { return m.begin(); }
|
|
const_iterator end() const { return m.end(); }
|
|
const_iterator cbegin() const { return m.cbegin(); }
|
|
const_iterator cend() const { return m.cend(); }
|
|
};
|
|
|
|
#endif // BITCOIN_INDIRECTMAP_H
|