mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
remoed nullableptr
This commit is contained in:
parent
88d8bf7cec
commit
ce53653ecd
2 changed files with 2 additions and 59 deletions
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
// This file contains common forward declarations.
|
||||
|
||||
namespace chatterino {
|
||||
class Channel;
|
||||
class ChannelView;
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
template <typename T>
|
||||
class NullablePtr
|
||||
{
|
||||
public:
|
||||
NullablePtr()
|
||||
: element_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
NullablePtr(T *element)
|
||||
: element_(element)
|
||||
{
|
||||
}
|
||||
|
||||
T *operator->() const
|
||||
{
|
||||
assert(this->hasElement());
|
||||
|
||||
return element_;
|
||||
}
|
||||
|
||||
T &operator*() const
|
||||
{
|
||||
assert(this->hasElement());
|
||||
|
||||
return *element_;
|
||||
}
|
||||
|
||||
T *get() const
|
||||
{
|
||||
assert(this->hasElement());
|
||||
|
||||
return this->element_;
|
||||
}
|
||||
|
||||
bool isNull() const
|
||||
{
|
||||
return this->element_ == nullptr;
|
||||
}
|
||||
|
||||
bool hasElement() const
|
||||
{
|
||||
return this->element_ != nullptr;
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return this->hasElement();
|
||||
}
|
||||
|
||||
private:
|
||||
T *element_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
Loading…
Reference in a new issue