userver: userver/dump/meta.hpp Source File
Loading...
Searching...
No Matches
meta.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/dump/meta.hpp
4/// @brief Provides dump::kIsDumpable and includes userver/dump/fwd.hpp
5
6#include <type_traits>
7
8#include <userver/dump/fwd.hpp>
9#include <userver/utils/meta_light.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace dump {
14
15namespace impl {
16
17template <typename T>
18using WritableResult =
19 decltype(Write(std::declval<Writer&>(), std::declval<const T&>()));
20
21template <typename T>
22using ReadableResult = decltype(Read(std::declval<Reader&>(), To<T>{}));
23
24} // namespace impl
25
26/// Check if `writer.Write(T)` is available
27template <typename T>
28inline constexpr bool kIsWritable =
30
31/// Check if `reader.Read<T>()` is available
32template <typename T>
33inline constexpr bool kIsReadable =
36
37/// Check if `T` is both writable and readable
38template <typename T>
39inline constexpr bool kIsDumpable = kIsWritable<T> && kIsReadable<T>;
40
41template <typename T>
42constexpr bool CheckDumpable() {
43 static_assert(
44 kIsDumpable<T>,
45 "Type is not dumpable. Probably you forgot to include "
46 "<userver/dump/common.hpp>, <userver/dump/common_containers.hpp> or "
47 "other headers with Read and Write declarations");
48
49 return true;
50}
51
52} // namespace dump
53
54USERVER_NAMESPACE_END