33// / @file userver/dump/meta.hpp
44// / @brief Provides dump::kIsDumpable and includes userver/dump/fwd.hpp
55
6+ #include < concepts>
67#include < type_traits>
78
89#include < userver/dump/fwd.hpp>
9- #include < userver/utils/meta_light.hpp>
1010
1111USERVER_NAMESPACE_BEGIN
1212
1313namespace dump {
1414
15- namespace impl {
16-
17- template <typename T>
18- using WritableResult = decltype (Write(std::declval<Writer&>(), std::declval<const T&>()));
19-
20- template <typename T>
21- using ReadableResult = decltype (Read(std::declval<Reader&>(), To<T>{}));
22-
23- } // namespace impl
24-
2515// / Check if `writer.Write(T)` is available
2616template <typename T>
27- inline constexpr bool kIsWritable = std::is_same_v<meta::DetectedType<impl::WritableResult, T>, void >;
17+ // NOLINTNEXTLINE(readability-identifier-naming)
18+ concept IsWritable = requires (Writer& writer, const T& value) {
19+ {
20+ Write (writer, value)
21+ } -> std::same_as<void >;
22+ };
2823
2924// / Check if `reader.Read<T>()` is available
3025template <typename T>
31- inline constexpr bool kIsReadable = std::is_same_v<meta::DetectedType<impl::ReadableResult, T>, std::remove_const_t <T>>;
26+ // NOLINTNEXTLINE(readability-identifier-naming)
27+ concept IsReadable = requires (Reader& reader) {
28+ {
29+ Read (reader, To<T>{})
30+ } -> std::same_as<std::remove_const_t <T>>;
31+ };
3232
3333// / Check if `T` is both writable and readable
3434template <typename T>
35- inline constexpr bool kIsDumpable = kIsWritable <T> && kIsReadable <T>;
35+ // NOLINTNEXTLINE(readability-identifier-naming)
36+ concept IsDumpable = IsWritable<T> && IsReadable<T>;
3637
3738template <typename T>
3839constexpr bool CheckDumpable () {
3940 static_assert (
40- kIsDumpable <T>,
41+ IsDumpable <T>,
4142 " Type is not dumpable. Probably you forgot to include "
4243 " <userver/dump/common.hpp>, <userver/dump/common_containers.hpp> or "
4344 " other headers with Read and Write declarations"
@@ -46,6 +47,21 @@ constexpr bool CheckDumpable() {
4647 return true ;
4748}
4849
50+ // / @deprecated Use @ref dump::IsWritable instead.
51+ template <typename T>
52+ // NOLINTNEXTLINE(readability-identifier-naming)
53+ concept kIsWritable = IsWritable<T>;
54+
55+ // / @deprecated Use @ref dump::IsReadable instead.
56+ template <typename T>
57+ // NOLINTNEXTLINE(readability-identifier-naming)
58+ concept kIsReadable = IsReadable<T>;
59+
60+ // / @deprecated Use @ref dump::IsDumpable instead.
61+ template <typename T>
62+ // NOLINTNEXTLINE(readability-identifier-naming)
63+ concept kIsDumpable = IsDumpable<T>;
64+
4965} // namespace dump
5066
5167USERVER_NAMESPACE_END
0 commit comments