mirror of
https://github.com/silverqx/TinyORM.git
synced 2025-12-20 09:59:53 -06:00
enhanced NotNull
Use Q_ASSERT_X() for Debug builds.
This commit is contained in:
@@ -7,7 +7,11 @@ TINY_SYSTEM_HEADER
|
|||||||
|
|
||||||
#include <orm/macros/commonnamespace.hpp>
|
#include <orm/macros/commonnamespace.hpp>
|
||||||
|
|
||||||
#include <exception>
|
#ifdef TINYDRIVERS_DEBUG
|
||||||
|
# include <type_traits>
|
||||||
|
#else
|
||||||
|
# include <exception>
|
||||||
|
#endif
|
||||||
|
|
||||||
TINYORM_BEGIN_COMMON_NAMESPACE
|
TINYORM_BEGIN_COMMON_NAMESPACE
|
||||||
|
|
||||||
@@ -58,15 +62,25 @@ namespace Private
|
|||||||
constexpr NotNull(U &&u) // NOLINT(google-explicit-constructor)
|
constexpr NotNull(U &&u) // NOLINT(google-explicit-constructor)
|
||||||
: m_ptr(std::forward<U>(u))
|
: m_ptr(std::forward<U>(u))
|
||||||
{
|
{
|
||||||
|
#ifdef TINYDRIVERS_DEBUG
|
||||||
|
Q_ASSERT_X(m_ptr != nullptr, "Drivers::NotNull",
|
||||||
|
"NotNull pointer can't be nullptr.");
|
||||||
|
#else
|
||||||
if (m_ptr == nullptr)
|
if (m_ptr == nullptr)
|
||||||
std::terminate();
|
std::terminate();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr NotNull(T u) requires (!std::is_same_v<std::nullptr_t, T>) // NOLINT(google-explicit-constructor)
|
constexpr NotNull(T u) requires (!std::is_same_v<std::nullptr_t, T>) // NOLINT(google-explicit-constructor)
|
||||||
: m_ptr(std::move(u))
|
: m_ptr(std::move(u))
|
||||||
{
|
{
|
||||||
|
#ifdef TINYDRIVERS_DEBUG
|
||||||
|
Q_ASSERT_X(m_ptr != nullptr, "Drivers::NotNull",
|
||||||
|
"NotNull pointer can't be nullptr.");
|
||||||
|
#else
|
||||||
if (m_ptr == nullptr)
|
if (m_ptr == nullptr)
|
||||||
std::terminate();
|
std::terminate();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::convertible_to<T> U>
|
template<std::convertible_to<T> U>
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ TINY_SYSTEM_HEADER
|
|||||||
|
|
||||||
#include "orm/macros/commonnamespace.hpp"
|
#include "orm/macros/commonnamespace.hpp"
|
||||||
|
|
||||||
#include <exception>
|
#ifdef TINYORM_DEBUG
|
||||||
|
# include <type_traits>
|
||||||
|
#else
|
||||||
|
# include <exception>
|
||||||
|
#endif
|
||||||
|
|
||||||
TINYORM_BEGIN_COMMON_NAMESPACE
|
TINYORM_BEGIN_COMMON_NAMESPACE
|
||||||
|
|
||||||
@@ -58,15 +62,23 @@ namespace Private
|
|||||||
constexpr NotNull(U &&u) // NOLINT(google-explicit-constructor)
|
constexpr NotNull(U &&u) // NOLINT(google-explicit-constructor)
|
||||||
: m_ptr(std::forward<U>(u))
|
: m_ptr(std::forward<U>(u))
|
||||||
{
|
{
|
||||||
|
#ifdef TINYORM_DEBUG
|
||||||
|
Q_ASSERT_X(m_ptr != nullptr, "NotNull", "NotNull pointer can't be nullptr.");
|
||||||
|
#else
|
||||||
if (m_ptr == nullptr)
|
if (m_ptr == nullptr)
|
||||||
std::terminate();
|
std::terminate();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr NotNull(T u) requires (!std::is_same_v<std::nullptr_t, T>) // NOLINT(google-explicit-constructor)
|
constexpr NotNull(T u) requires (!std::is_same_v<std::nullptr_t, T>) // NOLINT(google-explicit-constructor)
|
||||||
: m_ptr(std::move(u))
|
: m_ptr(std::move(u))
|
||||||
{
|
{
|
||||||
|
#ifdef TINYORM_DEBUG
|
||||||
|
Q_ASSERT_X(m_ptr != nullptr, "NotNull", "NotNull pointer can't be nullptr.");
|
||||||
|
#else
|
||||||
if (m_ptr == nullptr)
|
if (m_ptr == nullptr)
|
||||||
std::terminate();
|
std::terminate();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::convertible_to<T> U>
|
template<std::convertible_to<T> U>
|
||||||
|
|||||||
Reference in New Issue
Block a user