userver: userver/storages/mysql/convert.hpp Source File
Loading...
Searching...
No Matches
convert.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/mysql/convert.hpp
4/// @brief MySQL value conversion tag `To` and helper `DoConvert`
5
6#include <type_traits>
7#include <utility>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace storages::mysql::convert {
12
13template <typename T>
14struct To final {};
15
16namespace impl {
17
18template <typename T, typename DbType>
19concept HasConvert = requires(DbType&& from) { Convert(std::forward<DbType>(from), convert::To<T>{}); };
20
21} // namespace impl
22
23template <typename T, typename DbType>
24T DoConvert(DbType&& from) {
25 static_assert(
26 // TODO : better wording
27 impl::HasConvert<T, DbType>,
28 "There is no 'T Convert(From&&, storages::mysql::convert::To<T>)' in "
29 "neither namespace of 'T' or `storages::mysql::convert`"
30 );
31
32 return Convert(std::forward<DbType>(from), To<T>{});
33}
34
35} // namespace storages::mysql::convert
36
37USERVER_NAMESPACE_END