memgraph/poc/option_ptr.hpp
Dominik Gleich fcecb14545 Replace debug_assert, permanent_assert with DCHECK/CHECK
Summary:
Phase 2.

Phase 3.

Phase 4.

Phase 5.

Complete refactor.

Reviewers: florijan, mislav.bradac

Reviewed By: mislav.bradac

Subscribers: mislav.bradac, pullbot

Differential Revision: https://phabricator.memgraph.io/D895
2017-10-11 14:43:32 +02:00

27 lines
444 B
C++

#pragma once
#include "glog/logging.h"
// 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() {
DCHECK(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);
}