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 = decltype(Convert(std::declval<DbType&&>(), convert::To<T>{}));
19
20template <typename T, typename DbType>
21inline constexpr bool kHasConvert = meta::kIsDetected<HasConvert, T, DbType>;
22
23} // namespace impl
24
25template <typename T, typename DbType>
26T DoConvert(DbType&& from) {
27 static_assert(
28 // TODO : better wording
29 impl::kHasConvert<T, DbType>,
30 "There is no 'T Convert(From&&, storages::mysql::convert::To<T>)' in "
31 "neither namespace of 'T' or `storages::mysql::convert`"
32 );
33
34 return Convert(std::forward<DbType>(from), To<T>{});
35}
36
37} // namespace storages::mysql::convert
38
39USERVER_NAMESPACE_END