skullc-peripherals/Utility/Inc/utility_notnull.hpp
erki a7495db03f
All checks were successful
CI & Unit Tests / Unit-Tests (push) Successful in 1m34s
Utility: add notnull
2023-10-25 11:39:55 +03:00

52 lines
673 B
C++

//
// Created by erki on 25/10/23.
//
#pragma once
#include "utility_assert.hpp"
namespace Utility
{
template<typename T>
struct NotNull
{
NotNull(T* ptr)
: ptr_(ptr)
{
SKULLC_ASSERT_DEBUG(ptr_ != nullptr);
}
NotNull() = delete;
NotNull(const NotNull&) = delete;
NotNull(NotNull&&) = delete;
NotNull& operator=(const NotNull&) = delete;
NotNull& operator=(NotNull&&) = delete;
const T& operator*() const
{
return *ptr_;
}
T& operator*()
{
return *ptr_;
}
const T* operator->() const noexcept
{
return ptr_;
}
T* operator->() noexcept
{
return ptr_;
}
private:
T* ptr_;
};
}// namespace Utility