userver: userver/storages/postgres/io/nullable_traits.hpp Source File
Loading...
Searching...
No Matches
nullable_traits.hpp
1#pragma once
2
3#include <type_traits>
4
5#include <userver/compiler/demangle.hpp>
6#include <userver/storages/postgres/exceptions.hpp>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace storages::postgres::io::traits {
11
12/// @brief Metafunction to detect nullability of a type.
13template <typename T>
14struct IsNullable : std::false_type {};
15
16template <typename T>
17concept kIsNullable = IsNullable<T>::value; // NOLINT(readability-identifier-naming)
18
19template <typename T>
20struct GetSetNull {
21 inline static bool IsNull(const T&) { return false; }
22 inline static void SetNull(T&) {
23 // TODO Consider a static_assert here
24 throw TypeCannotBeNull(compiler::GetTypeName<T>());
25 }
26 inline static void SetDefault(T& value) { value = T{}; }
27};
28
29} // namespace storages::postgres::io::traits
30
31USERVER_NAMESPACE_END