memgraph/poc/option_ptr.hpp
Mislav Bradac 0588de76bb Move unused datastructures to poc
Reviewers: buda

Reviewed By: buda

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D526
2017-07-10 12:03:11 +02:00

27 lines
450 B
C++

#pragma once
#include "utils/assert.hpp"
// Like option just for pointers. More efficent than option.
template <class T>
class OptionPtr {
public:
OptionPtr() {}
OptionPtr(T *ptr) : ptr(ptr) {}
bool is_present() { return ptr != nullptr; }
T *get() {
debug_assert(is_present(), "Data is not present.");
return ptr;
}
private:
T *ptr = nullptr;
};
template <class T>
auto make_option_ptr(T *t) {
return OptionPtr<T>(t);
}