Key is not default constructible anymore

This commit is contained in:
Sebastian Messmer 2015-04-17 12:59:40 +02:00
parent 4a5416dbec
commit 75253c74ea
2 changed files with 10 additions and 6 deletions

View File

@ -14,12 +14,12 @@ namespace caching {
template<class Key, class Value> template<class Key, class Value>
class QueueMap { class QueueMap {
public: public:
QueueMap(): _entries(), _sentinel(Key(), nullptr, &_sentinel, &_sentinel) { QueueMap(): _entries(), _sentinel(nullptr, nullptr, &_sentinel, &_sentinel) {
} }
virtual ~QueueMap() {} virtual ~QueueMap() {}
void push(const Key &key, std::unique_ptr<Value> value) { void push(const Key &key, std::unique_ptr<Value> value) {
auto newEntry = std::make_unique<Entry>(key, std::move(value), _sentinel.prev, &_sentinel); auto newEntry = std::make_unique<Entry>(&key, std::move(value), _sentinel.prev, &_sentinel);
_sentinel.prev->next = newEntry.get(); _sentinel.prev->next = newEntry.get();
_sentinel.prev = newEntry.get(); _sentinel.prev = newEntry.get();
auto insertResult = _entries.emplace(key, std::move(newEntry)); auto insertResult = _entries.emplace(key, std::move(newEntry));
@ -38,7 +38,7 @@ public:
} }
std::unique_ptr<Value> pop() { std::unique_ptr<Value> pop() {
return pop(_sentinel.next->key); return pop(*_sentinel.next->key);
} }
uint32_t size() { uint32_t size() {
@ -47,8 +47,12 @@ public:
private: private:
struct Entry { struct Entry {
Entry(const Key &key_, std::unique_ptr<Value> value_, Entry *prev_, Entry *next_): key(key_), value(std::move(value_)), prev(prev_), next(next_) {} Entry(const Key *key_, std::unique_ptr<Value> value_, Entry *prev_, Entry *next_): key(nullptr), value(std::move(value_)), prev(prev_), next(next_) {
Key key; if (key_ != nullptr) {
key = std::make_unique<Key>(*key_);
}
}
std::unique_ptr<Key> key;
std::unique_ptr<Value> value; std::unique_ptr<Value> value;
Entry *prev; Entry *prev;
Entry *next; Entry *next;

View File

@ -12,7 +12,6 @@ namespace blockstore {
template<int SIZE> template<int SIZE>
class FixedSizeData { class FixedSizeData {
public: public:
FixedSizeData() {}
//Non-virtual destructor because we want objects to be small //Non-virtual destructor because we want objects to be small
~FixedSizeData() {} ~FixedSizeData() {}
@ -30,6 +29,7 @@ public:
const unsigned char *data() const; const unsigned char *data() const;
private: private:
FixedSizeData() {}
static CryptoPP::AutoSeededRandomPool &RandomPool(); static CryptoPP::AutoSeededRandomPool &RandomPool();
unsigned char _data[BINARY_LENGTH]; unsigned char _data[BINARY_LENGTH];