Added is_nullable

This commit is contained in:
Dr. Patrick Urbanke
2025-03-22 03:56:16 +01:00
parent 2ab4aa1099
commit 2fdfc967f5
2 changed files with 53 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
#ifndef SQLGEN_PARSING_HAS_REFLECTION_TYPE_HPP_
#define SQLGEN_PARSING_HAS_REFLECTION_TYPE_HPP_
#include <concepts>
namespace sqlgen::parsing {
template <typename T>
concept has_reflection_method = requires(T _t) {
{ _t.reflection() } -> std::convertible_to<typename T::ReflectionType>;
};
} // namespace sqlgen::parsing
#endif

View File

@@ -0,0 +1,38 @@
#ifndef SQLGEN_PARSING_IS_NULLABLE_HPP_
#define SQLGEN_PARSING_IS_NULLABLE_HPP_
#include <memory>
#include <optional>
#include <type_traits>
namespace sqlgen::parsing {
/// Determines whether a field in a named tuple is required.
/// General case - most fields are required.
template <class T>
class has_nullopt;
template <class T>
class has_nullopt : public std::false_type {};
template <class T>
class has_nullopt<std::optional<T>> : public std::true_type {};
template <class T>
class has_nullopt<std::shared_ptr<T>> : public std::true_type {};
template <class T>
class has_nullopt<std::unique_ptr<T>> : public std::true_type {};
template <class T>
consteval bool is_nullable() {
if constexpr (has_reflection_method<T>) {
return is_nullable<typename T::ReflectionType>();
} else {
return has_nullopt<T>::value;
}
}
} // namespace sqlgen::parsing
#endif