Skip to content

Commit 3185ba9

Browse files
committed
Correct directory name and refactor valarray
1 parent 26ab13e commit 3185ba9

File tree

7 files changed

+44
-4
lines changed

7 files changed

+44
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ add_subdirectory("VariadicTemplateParameter")
4141
add_subdirectory("Vector")
4242
add_subdirectory("View")
4343
add_subdirectory("VirtualPointer")
44-
add_subdirectory("WriteAccessStructralBinding")
44+
add_subdirectory("WriteAccessStructuralBinding")

Util/type_name.hh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @file type_name.hh
3+
* @author Xuhua Huang
4+
* @brief
5+
* @version 0.1
6+
* @date 2025-09-23
7+
*
8+
* @copyright Copyright (c) 2025
9+
*
10+
*/
11+
12+
#ifndef TYPE_NAME_HH
13+
#define TYPE_NAME_HH
14+
15+
#include <string_view>
16+
17+
namespace util {
18+
namespace type {
19+
20+
template <typename T> constexpr std::string_view type_name() {
21+
#if defined(__clang__)
22+
std::string_view p = __PRETTY_FUNCTION__;
23+
return p.substr(p.find('=') + 2, p.rfind(']') - p.find('=') - 2);
24+
#elif defined(__GNUC__)
25+
std::string_view p = __PRETTY_FUNCTION__;
26+
return p.substr(p.find('=') + 2, p.rfind(']') - p.find('=') - 2);
27+
#elif defined(_MSC_VER)
28+
std::string_view p = __FUNCSIG__;
29+
auto start = p.find("type_name<") + 10;
30+
auto end = p.find(">(void)");
31+
return p.substr(start, end - start);
32+
#else
33+
#error "Unsupported compiler"
34+
#endif
35+
}
36+
37+
} // namespace type
38+
} // namespace util
39+
40+
#endif //! TYPE_NAME_HH

ValArray/valarray_notes.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ int main() {
7474
log << val << "\n";
7575
log << val.size() << "\n";
7676
val.resize(1);
77-
val[0] = 3.14;
77+
val[0] = 3.14F;
7878
log << val << "\n";
7979

8080
val.resize(2);
81-
val[1] = 2.71;
81+
val[1] = 2.71F;
8282
log << val << "\n";
8383

8484
// create a valarray of size 5, initialized with values 0, 1, 2, 3, 4
@@ -102,7 +102,7 @@ int main() {
102102
auto v4 = v3.apply([](int x) -> int { return x / 2; });
103103
log << "v4 is of type std::valarray<int>: "
104104
<< std::is_same_v<decltype(v4), std::valarray<int>> << "\n";
105-
log << typeid(v4).name() << "\n"; // class std::valarray<int>
105+
log << typeid(v4).name() << "\n"; // class std::valarray<int>
106106
#if defined(__GNUC__)
107107
log << type_name<decltype(v4)>() << "\n";
108108
#elif defined(_MSC_VER)
File renamed without changes.

0 commit comments

Comments
 (0)