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 = decltype(Write(std::declval<Writer&>(), std::declval<const T&>()));
19
20template <typename T>
21using ReadableResult = decltype(Read(std::declval<Reader&>(), To<T>{}));
22
23} // namespace impl
24
25/// Check if `writer.Write(T)` is available
26template <typename T>
27inline constexpr bool kIsWritable = std::is_same_v<meta::DetectedType<impl::WritableResult, T>, void>;
28
29/// Check if `reader.Read<T>()` is available
30template <typename T>
32
33/// Check if `T` is both writable and readable
34template <typename T>
35inline constexpr bool kIsDumpable = kIsWritable<T> && kIsReadable<T>;
36
37template <typename T>
38constexpr bool CheckDumpable() {
39 static_assert(
40 kIsDumpable<T>,
41 "Type is not dumpable. Probably you forgot to include "
42 "<userver/dump/common.hpp>, <userver/dump/common_containers.hpp> or "
43 "other headers with Read and Write declarations"
44 );
45
46 return true;
47}
48
49} // namespace dump
50
51USERVER_NAMESPACE_END