userver: userver/storages/mysql/convert.hpp Source File
Loading...
Searching...
No Matches
convert.hpp
1#pragma once
2
3#include <type_traits>
4#include <utility>
5
6#include <userver/utils/meta_light.hpp>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace storages::mysql::convert {
11
12template <typename T>
13struct To final {};
14
15namespace impl {
16
17template <typename T, typename DbType>
18using HasConvert =
19 decltype(Convert(std::declval<DbType&&>(), convert::To<T>{}));
20
21template <typename T, typename DbType>
22inline constexpr bool kHasConvert = meta::kIsDetected<HasConvert, T, DbType>;
23
24} // namespace impl
25
26template <typename T, typename DbType>
27T DoConvert(DbType&& from) {
28 static_assert(
29 // TODO : better wording
30 impl::kHasConvert<T, DbType>,
31 "There is no 'T Convert(From&&, storages::mysql::convert::To<T>)' in "
32 "neither namespace of 'T' or `storages::mysql::convert`");
33
34 return Convert(std::forward<DbType>(from), To<T>{});
35}
36
37} // namespace storages::mysql::convert
38
39USERVER_NAMESPACE_END