aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryurial <yurial@yandex-team.com>2023-11-15 19:04:49 +0300
committeryurial <yurial@yandex-team.com>2023-11-15 20:41:53 +0300
commit74b9f490cb9b078ae8675a7aa0947657371e294b (patch)
treeb758a0d34c536195f36921b7a8e3cc85111cd3d6
parentc3af3ff02e15d03164a4b79b042490e41ce7c473 (diff)
downloadydb-74b9f490cb9b078ae8675a7aa0947657371e294b.tar.gz
Allow to handle Y_SAVELOAD_DEFINE() without args
-rw-r--r--util/ysaveload.h40
-rw-r--r--util/ysaveload_ut.cpp13
2 files changed, 37 insertions, 16 deletions
diff --git a/util/ysaveload.h b/util/ysaveload.h
index 8771f1e4a1..52fd5bd8ef 100644
--- a/util/ysaveload.h
+++ b/util/ysaveload.h
@@ -726,24 +726,32 @@ static inline void LoadMany(S* s, Ts&... t) {
ApplyToMany([&](auto& v) { Load(s, v); }, t...);
}
-#define Y_SAVELOAD_DEFINE(...) \
- inline void Save(IOutputStream* s) const { \
- ::SaveMany(s, __VA_ARGS__); \
- } \
- \
- inline void Load(IInputStream* s) { \
- ::LoadMany(s, __VA_ARGS__); \
- } \
+#define Y_SAVELOAD_DEFINE(...) \
+ inline void Save(IOutputStream* s) const { \
+ [s](auto&&... args) { \
+ ::SaveMany(s, std::forward<decltype(args)>(args)...); \
+ }(__VA_ARGS__); \
+ } \
+ \
+ inline void Load(IInputStream* s) { \
+ [s](auto&&... args) { \
+ ::LoadMany(s, std::forward<decltype(args)>(args)...); \
+ }(__VA_ARGS__); \
+ } \
Y_SEMICOLON_GUARD
-#define Y_SAVELOAD_DEFINE_OVERRIDE(...) \
- void Save(IOutputStream* s) const override { \
- ::SaveMany(s, __VA_ARGS__); \
- } \
- \
- void Load(IInputStream* s) override { \
- ::LoadMany(s, __VA_ARGS__); \
- } \
+#define Y_SAVELOAD_DEFINE_OVERRIDE(...) \
+ void Save(IOutputStream* s) const override { \
+ [s](auto&&... args) { \
+ ::SaveMany(s, std::forward<decltype(args)>(args)...); \
+ }(__VA_ARGS__); \
+ } \
+ \
+ void Load(IInputStream* s) override { \
+ [s](auto&&... args) { \
+ ::LoadMany(s, std::forward<decltype(args)>(args)...); \
+ }(__VA_ARGS__); \
+ } \
Y_SEMICOLON_GUARD
template <class T>
diff --git a/util/ysaveload_ut.cpp b/util/ysaveload_ut.cpp
index 23152ed929..38f1e3bde5 100644
--- a/util/ysaveload_ut.cpp
+++ b/util/ysaveload_ut.cpp
@@ -22,6 +22,7 @@ static inline char* AllocateFromPool(TMemoryPool& pool, size_t len) {
class TSaveLoadTest: public TTestBase {
UNIT_TEST_SUITE(TSaveLoadTest);
UNIT_TEST(TestSaveLoad)
+ UNIT_TEST(TestSaveLoadEmptyStruct)
UNIT_TEST(TestNewStyle)
UNIT_TEST(TestNewNewStyle)
UNIT_TEST(TestList)
@@ -61,6 +62,10 @@ class TSaveLoadTest: public TTestBase {
Y_SAVELOAD_DEFINE(Str, Int);
};
+ struct TNewNewStyleEmptyHelper {
+ Y_SAVELOAD_DEFINE();
+ };
+
private:
inline void TestNewNewStyle() {
TString ss;
@@ -375,6 +380,14 @@ private:
}
}
+ inline void TestSaveLoadEmptyStruct() {
+ TBufferStream S_;
+ TNewNewStyleEmptyHelper h;
+
+ Save(&S_, h);
+ Load(&S_, h);
+ }
+
void TestList() {
TBufferStream s;