Skip to content

Commit 171e326

Browse files
committed
Create serialize.hpp
1 parent bbe79a4 commit 171e326

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Util/stdcxx26/serialize.hpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @file serialize.hpp
3+
* @author Xuhua Huang
4+
* @brief
5+
* @version 0.1
6+
* @date 2025-06-19
7+
*
8+
* @copyright Copyright (c) 2025
9+
*
10+
*/
11+
12+
#pragma once
13+
#ifndef SERIALIZE_HPP
14+
#define SERIALIZE_HPP
15+
16+
#include <print>
17+
18+
namespace util {
19+
20+
void inspect(const auto& obj) {
21+
const auto& [...values] = obj;
22+
23+
std::print("Object has: {} elements\n", sizeof...(values));
24+
25+
int count = 0;
26+
27+
(std::print("Elem: {}: {}\n", count++, values), ...);
28+
}
29+
30+
void serialize(const auto& obj) {
31+
const auto& [...values] = obj;
32+
static_assert(sizeof...(values) == std::size(obj.names));
33+
34+
std::size_t index = 0;
35+
std::print("{{");
36+
(std::print("\"{}\": {}, ", obj.names[index++], values), ...);
37+
std::print("}}");
38+
}
39+
40+
}
41+
42+
#endif // !SERIALIZE_HPP

0 commit comments

Comments
 (0)