Skip to content

Commit

Permalink
Remove space while formatting multi-dim arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
winwinashwin authored and sharkdp committed Jan 17, 2023
1 parent 4880b9b commit 9c5a5a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,21 +224,21 @@ inline std::string get_type_name(type_tag<std::string>) {

template <typename T>
typename std::enable_if<(std::rank<T>::value == 1), std::string>::type
get_dim() {
get_array_dim() {
return "[" + std::to_string(std::extent<T>::value) + "]";
}

template <typename T>
typename std::enable_if<(std::rank<T>::value > 1), std::string>::type
get_dim() {
get_array_dim() {
return "[" + std::to_string(std::extent<T>::value) + "]" +
get_dim<typename std::remove_extent<T>::type>();
get_array_dim<typename std::remove_extent<T>::type>();
}

template <typename T>
typename std::enable_if<(std::rank<T>::value > 0), std::string>::type
get_type_name(type_tag<T>) {
return type_name<typename std::remove_all_extents<T>::type>() + " " + get_dim<T>();
return type_name<typename std::remove_all_extents<T>::type>() + get_array_dim<T>();
}

template <typename T, size_t N>
Expand Down
6 changes: 3 additions & 3 deletions tests/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ TEST_CASE("type_name") {

SECTION("C-style arrays") {
CHECK(type_name<int[3]>() ==
(std::is_same<int, int32_t>::value ? "int32_t [3]" : "int [3]"));
CHECK(type_name<char[1][2][3]>() == "char [1][2][3]");
(std::is_same<int, int32_t>::value ? "int32_t[3]" : "int[3]"));
CHECK(type_name<char[1][2][3]>() == "char[1][2][3]");
double a[] = {5, 4, 3, 2, 1};
CHECK(type_name<decltype(a)>() == "double [5]");
CHECK(type_name<decltype(a)>() == "double[5]");
}

SECTION("const and volatile") {
Expand Down

0 comments on commit 9c5a5a3

Please sign in to comment.