Skip to content

Commit

Permalink
Add metainformation for dbg::type<T>()
Browse files Browse the repository at this point in the history
Branch: dbg-type-add-metainformation
  • Loading branch information
David Peter authored and sharkdp committed Mar 11, 2020
1 parent 1a1b798 commit 4f7a7a5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
18 changes: 18 additions & 0 deletions dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,24 @@ inline bool pretty_print(std::ostream& stream,
template <typename T>
inline bool pretty_print(std::ostream& stream, const print_type<T>&) {
stream << type_name<T>();

stream << " [sizeof: " << sizeof(T) << " byte, ";

stream << "trivial: ";
if (std::is_trivial<T>::value) {
stream << "yes";
} else {
stream << "no";
}

stream << ", standard layout: ";
if (std::is_standard_layout<T>::value) {
stream << "yes";
} else {
stream << "no";
}
stream << "]";

return false;
}

Expand Down
16 changes: 14 additions & 2 deletions tests/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int main() {

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

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

class user_defined_class {
public:
user_defined_class() {}
void some_method(int x) { dbg(x); }
};
user_defined_class{}.some_method(42);
Expand All @@ -132,9 +133,20 @@ int main() {

dbg("====== type names without a value");
using IsSame = std::is_same<uint8_t, char>::type;

struct user_defined_trivial_type {
int32_t a;
bool b;
};

dbg(dbg::type<IsSame>());
dbg(dbg::type<int32_t>());
dbg(dbg::type<const int32_t>());
dbg(dbg::type<int32_t*>());
dbg(dbg::type<int32_t&>());
dbg(dbg::type<user_defined_trivial_type>());
dbg(dbg::type<user_defined_class>());

dbg("====== timestamp");
dbg(dbg::time());

}

0 comments on commit 4f7a7a5

Please sign in to comment.