Vulkan-Hpp/snippets/Optional.hpp

34 lines
624 B
C++
Raw Normal View History

template <typename RefType>
class Optional
{
public:
Optional( RefType & reference ) VULKAN_HPP_NOEXCEPT
{
m_ptr = &reference;
}
Optional( RefType * ptr ) VULKAN_HPP_NOEXCEPT
{
m_ptr = ptr;
}
Optional( std::nullptr_t ) VULKAN_HPP_NOEXCEPT
{
m_ptr = nullptr;
}
operator RefType *() const VULKAN_HPP_NOEXCEPT
{
return m_ptr;
}
RefType const * operator->() const VULKAN_HPP_NOEXCEPT
{
return m_ptr;
}
explicit operator bool() const VULKAN_HPP_NOEXCEPT
{
return !!m_ptr;
}
private:
RefType * m_ptr;
};