mirror of
https://github.com/getml/sqlgen.git
synced 2026-01-07 18:09:32 -06:00
Added is_nullable
This commit is contained in:
15
include/parsing/has_reflection_method.hpp
Normal file
15
include/parsing/has_reflection_method.hpp
Normal 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
|
||||
38
include/parsing/is_nullable.hpp
Normal file
38
include/parsing/is_nullable.hpp
Normal 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
|
||||
Reference in New Issue
Block a user