#pragma once #include #include #include #include #include namespace NSQLComplete { template struct TByteSize; template requires std::is_fundamental_v struct TByteSize { size_t operator()(const T& x) const noexcept { return sizeof(x); } }; template struct TByteSize> { size_t operator()(const TVector& x) const noexcept { size_t bytes = sizeof(x); bytes = Accumulate(x, bytes, [](size_t acc, const T& x) { return acc + TByteSize()(x); }); bytes += x.capacity() * sizeof(T); return bytes; } }; template <> struct TByteSize { size_t operator()(const TString& x) const noexcept { return std::max(sizeof(x), sizeof(x) + x.capacity()); } }; template struct TByteSize> { size_t operator()(const TMaybe& x) const noexcept { return x.Transform([](const T& x) { return TByteSize()(x) - sizeof(T); }).GetOrElse(0) + sizeof(TMaybe); } }; template concept CByteSized = requires(const T& x) { { TByteSize()(x) } -> std::convertible_to; }; } // namespace NSQLComplete