Skip to content

Commit 4f7a7a5

Browse files
David Petersharkdp
authored andcommitted
Add metainformation for dbg::type<T>()
Branch: dbg-type-add-metainformation
1 parent 1a1b798 commit 4f7a7a5

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

dbg.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,24 @@ inline bool pretty_print(std::ostream& stream,
524524
template <typename T>
525525
inline bool pretty_print(std::ostream& stream, const print_type<T>&) {
526526
stream << type_name<T>();
527+
528+
stream << " [sizeof: " << sizeof(T) << " byte, ";
529+
530+
stream << "trivial: ";
531+
if (std::is_trivial<T>::value) {
532+
stream << "yes";
533+
} else {
534+
stream << "no";
535+
}
536+
537+
stream << ", standard layout: ";
538+
if (std::is_standard_layout<T>::value) {
539+
stream << "yes";
540+
} else {
541+
stream << "no";
542+
}
543+
stream << "]";
544+
527545
return false;
528546
}
529547

tests/demo.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int main() {
104104

105105
int8_t negative_five = -5;
106106
dbg(dbg::bin(negative_five));
107-
dbg(dbg::bin(static_cast<uint8_t>(negative_five))); // two's complement:
107+
dbg(dbg::bin(static_cast<uint8_t>(negative_five)));
108108

109109
dbg("====== std::tuple and std::pair");
110110
dbg(std::tuple<std::string, int, float>{"Hello", 7, 3.14f});
@@ -121,6 +121,7 @@ int main() {
121121

122122
class user_defined_class {
123123
public:
124+
user_defined_class() {}
124125
void some_method(int x) { dbg(x); }
125126
};
126127
user_defined_class{}.some_method(42);
@@ -132,9 +133,20 @@ int main() {
132133

133134
dbg("====== type names without a value");
134135
using IsSame = std::is_same<uint8_t, char>::type;
136+
137+
struct user_defined_trivial_type {
138+
int32_t a;
139+
bool b;
140+
};
141+
135142
dbg(dbg::type<IsSame>());
143+
dbg(dbg::type<int32_t>());
144+
dbg(dbg::type<const int32_t>());
145+
dbg(dbg::type<int32_t*>());
146+
dbg(dbg::type<int32_t&>());
147+
dbg(dbg::type<user_defined_trivial_type>());
148+
dbg(dbg::type<user_defined_class>());
136149

137150
dbg("====== timestamp");
138151
dbg(dbg::time());
139-
140152
}

0 commit comments

Comments
 (0)