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 <concepts>
7#include <type_traits>
8
9#include <userver/dump/fwd.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace dump {
14
15/// Check if `writer.Write(T)` is available
16template <typename T>
17// NOLINTNEXTLINE(readability-identifier-naming)
18concept IsWritable = requires(Writer& writer, const T& value) {
19 {
20 Write(writer, value)
21 } -> std::same_as<void>;
22};
23
24/// Check if `reader.Read<T>()` is available
25template <typename T>
26// NOLINTNEXTLINE(readability-identifier-naming)
27concept IsReadable = requires(Reader& reader) {
28 {
29 Read(reader, To<T>{})
30 } -> std::same_as<std::remove_const_t<T>>;
31};
32
33/// Check if `T` is both writable and readable
34template <typename T>
35// NOLINTNEXTLINE(readability-identifier-naming)
36concept IsDumpable = IsWritable<T> && IsReadable<T>;
37
38template <typename T>
39constexpr bool CheckDumpable() {
40 static_assert(
41 IsDumpable<T>,
42 "Type is not dumpable. Probably you forgot to include "
43 "<userver/dump/common.hpp>, <userver/dump/common_containers.hpp> or "
44 "other headers with Read and Write declarations"
45 );
46
47 return true;
48}
49
50/// @deprecated Use @ref dump::IsWritable instead.
51template <typename T>
52// NOLINTNEXTLINE(readability-identifier-naming)
53concept kIsWritable = IsWritable<T>;
54
55/// @deprecated Use @ref dump::IsReadable instead.
56template <typename T>
57// NOLINTNEXTLINE(readability-identifier-naming)
58concept kIsReadable = IsReadable<T>;
59
60/// @deprecated Use @ref dump::IsDumpable instead.
61template <typename T>
62// NOLINTNEXTLINE(readability-identifier-naming)
63concept kIsDumpable = IsDumpable<T>;
64
65} // namespace dump
66
67USERVER_NAMESPACE_END