memgraph/include/utils/option_ptr.hpp
Kruno Tomola Fabro d806d635f9 Added documentation.
Fixed test for index.
2016-09-18 23:22:36 +01:00

28 lines
415 B
C++

#pragma once
// 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()
{
assert(is_present());
return ptr;
}
private:
T *ptr = nullptr;
};
template <class T>
auto make_option_ptr(T *t)
{
return OptionPtr<T>(t);
}