2022-05-06 15:46:50 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_MISC_NOTNULLPTR_H
|
|
|
|
#define OPENMW_COMPONENTS_MISC_NOTNULLPTR_H
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
namespace Misc
|
|
|
|
{
|
|
|
|
template <class T>
|
|
|
|
class NotNullPtr
|
|
|
|
{
|
|
|
|
public:
|
2023-02-17 17:54:48 +00:00
|
|
|
constexpr NotNullPtr(T* value) noexcept
|
2022-05-06 15:46:50 +00:00
|
|
|
: mValue(value)
|
|
|
|
{
|
|
|
|
assert(mValue != nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
NotNullPtr(std::nullptr_t) = delete;
|
|
|
|
|
2023-02-17 17:54:48 +00:00
|
|
|
constexpr operator T*() const noexcept { return mValue; }
|
2022-05-06 15:46:50 +00:00
|
|
|
|
2023-02-17 17:54:48 +00:00
|
|
|
constexpr T* operator->() const noexcept { return mValue; }
|
2022-05-06 15:46:50 +00:00
|
|
|
|
2023-02-17 17:54:48 +00:00
|
|
|
constexpr T& operator*() const noexcept { return *mValue; }
|
2022-05-06 15:46:50 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
T* mValue;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|