|
26 | 26 | #endif // no system header |
27 | 27 |
|
28 | 28 | #include <cuda/std/__utility/exception_guard.h> |
| 29 | +#include <cuda/std/__utility/typeid.h> |
29 | 30 | #include <cuda/std/mdspan> |
30 | 31 |
|
31 | 32 | #include <cuda/experimental/__stf/utility/core.cuh> |
|
37 | 38 |
|
38 | 39 | namespace cuda::experimental::stf |
39 | 40 | { |
40 | | -namespace reserved |
41 | | -{ |
42 | | -// We use this function as a detector for what __PRETTY_FUNCTION__ looks like |
43 | | -template <typename T> |
44 | | -constexpr ::std::string_view type_name_IMPL() |
45 | | -{ |
46 | | -#if _CCCL_COMPILER(MSVC) |
47 | | - return __FUNCSIG__; |
48 | | -#else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC) vvv |
49 | | - return __PRETTY_FUNCTION__; |
50 | | -#endif // !_CCCL_COMPILER(MSVC) |
51 | | -} |
52 | | - |
53 | | -// Length of prefix and suffix in __PRETTY_FUNCTION__ when used with `type_name`. |
54 | | -inline constexpr ::std::pair<size_t, size_t> type_name_affixes = [] { |
55 | | - const auto p = type_name_IMPL<double>(); |
56 | | - const auto target = ::std::string_view("double"); |
57 | | - const auto len = target.size(); |
58 | | - // Simulate p.find() by hand because clang can't do it. |
59 | | - size_t i = target.npos; |
60 | | - for (std::size_t start = 0; start <= p.size() - len; ++start) |
61 | | - { |
62 | | - if (p.substr(start, len) == target) |
63 | | - { |
64 | | - i = start; // Found the substring, set i to the starting position |
65 | | - break; // Exit loop after finding the first match |
66 | | - } |
67 | | - } |
68 | | - auto j = p.size() - i - len; |
69 | | - return ::std::pair{i, j}; |
70 | | -}(); |
71 | | - |
72 | | -template <class T> |
73 | | -constexpr ::std::string_view type_name_impl() |
74 | | -{ |
75 | | -#if _CCCL_COMPILER(MSVC) |
76 | | - constexpr ::std::string_view p = __FUNCSIG__; |
77 | | - // MSVC does not provide constexpr methods so we make this utility much simpler and return __FUNCSIG__ directly |
78 | | - return p; |
79 | | -#else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC) vvv |
80 | | - ::std::string_view p = __PRETTY_FUNCTION__; |
81 | | - return p.substr(type_name_affixes.first, p.size() - type_name_affixes.first - type_name_affixes.second); |
82 | | -#endif // !_CCCL_COMPILER(MSVC) |
83 | | -} |
84 | | -} // namespace reserved |
85 | | - |
86 | 41 | /** |
87 | 42 | * @brief Yields a string form of type name. Exact spelling not guaranteed (e.g. `type_name<int*>` may be `"int*"`, |
88 | 43 | * `"int *"` etc). |
89 | 44 | * |
| 45 | + * Thin wrapper around `cuda::std::__pretty_nameof<T>()` returning `::std::string_view`. |
| 46 | + * |
90 | 47 | * @tparam T The type to show. |
91 | 48 | * |
92 | 49 | * @snippet unittest.h type_name |
93 | 50 | */ |
94 | 51 | template <class T> |
95 | | -inline constexpr ::std::string_view type_name = reserved::type_name_impl<T>(); |
| 52 | +inline const ::std::string_view type_name{ |
| 53 | + ::cuda::std::__pretty_nameof<T>().data(), ::cuda::std::__pretty_nameof<T>().size()}; |
96 | 54 |
|
97 | 55 | /** |
98 | 56 | * @brief Converts each element in `t` to a new value by calling `f`, then returns a tuple collecting the values thus |
|
0 commit comments