-
Notifications
You must be signed in to change notification settings - Fork 12
/
print_struct.cpp
36 lines (33 loc) · 864 Bytes
/
print_struct.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/// @example mirror/print_struct.cpp
///
/// Copyright Matus Chochlik.
/// Distributed under the Boost Software License, Version 1.0.
/// See accompanying file LICENSE_1_0.txt or copy at
/// http://www.boost.org/LICENSE_1_0.txt
///
#include <iostream>
#include <mirror/sequence.hpp>
template <typename S>
void print_struct(const S& x) {
std::cout << get_name(get_aliased(mirror(S)));
std::cout << '(';
for_each_info(
get_data_members(get_aliased(mirror(S))), [&](auto mo, auto info) {
if(!info.is_first()) {
std::cout << ", ";
}
std::cout << get_name(mo) << ": " << get_value(mo, x);
});
std::cout << ')' << std::endl;
}
struct mystruct {
std::string s{"str"};
float f{1.2F};
int i{345};
bool b{false};
};
int main() {
mystruct x;
print_struct(x);
return 0;
}