support bazel complie this project and format code.

This commit is contained in:
zhangxing
2023-03-30 00:15:11 +08:00
committed by light-city
parent 1f86192576
commit 3c8a3f259b
641 changed files with 10349 additions and 9523 deletions

View File

@@ -0,0 +1,35 @@
//
// Created by light on 20-1-6.
//
#include <boost/hana.hpp>
#include <iostream>
#include <string>
#include "structData.h"
using namespace std;
namespace hana = boost::hana;
// 检查类型是否有一个serialize方法
auto hasSerialize = hana::is_valid([](auto &&x) -> decltype(x.serialize()) {});
// 序列化任意对象
template<typename T>
std::string serialize(T const &obj) {
return hana::if_(hasSerialize(obj),
[](auto &x) { return x.serialize(); },
[](auto &x) { return to_string(x); }
)(obj);
}
int main() {
A a;
B b;
C c;
std::cout << serialize(a) << std::endl;
std::cout << serialize(b) << std::endl;
std::cout << serialize(c) << std::endl;
}