1717
1818#include < cassert>
1919#include < cstdint>
20- #include < cxxabi.h>
2120#include < iostream>
2221#include < memory>
2322#include < span>
2625#include < typeinfo>
2726#include < valarray>
2827
28+ #if defined(__GNUC__)
29+ #include < cxxabi.h>
30+
31+ template <typename T> [[nodiscard]] std::string type_name () {
32+ int status = 0 ;
33+ std::unique_ptr<char , void (*)(void *)> res{
34+ abi::__cxa_demangle (typeid (T).name (), nullptr , nullptr , &status),
35+ std::free};
36+ return (status == 0 ) ? res.get () : typeid (T).name ();
37+ }
38+ #endif
39+
2940#ifndef log
3041#define log std::cout << __LINE__ << " : " << std::boolalpha
3142#endif
@@ -51,14 +62,6 @@ inline std::ostream &
5162operator <<(std::ostream &os,
5263 const std::valarray<std::uint8_t > &values) noexcept = delete ;
5364
54- template <typename T> std::string type_name () {
55- int status = 0 ;
56- std::unique_ptr<char , void (*)(void *)> res{
57- abi::__cxa_demangle (typeid (T).name (), nullptr , nullptr , &status),
58- std::free};
59- return (status == 0 ) ? res.get () : typeid (T).name ();
60- }
61-
6265int main () {
6366 static_assert (std::is_arithmetic_v<std::uint8_t >);
6467
@@ -100,8 +103,11 @@ int main() {
100103 log << " v4 is of type std::valarray<int>: "
101104 << std::is_same_v<decltype (v4), std::valarray<int >> << " \n " ;
102105 log << typeid (v4).name () << " \n " ;
106+ #if defined(__GNUC__)
103107 log << type_name<decltype (v4)>() << " \n " ;
104- // log << v4 << "\n";
108+ #elif defined(_MSC_VER)
109+ log << v4 << " \n " ;
110+ #endif
105111
106112 // increment the value in v
107113 v += 1 ;
@@ -128,7 +134,9 @@ int main() {
128134 // s[2 + 2 + 2] == s[6] = 7
129135 std::slice s{2 , 3 , 2 };
130136 log << typeid (s).name () << " \n " ; // class std::slice
137+ #if defined(__GNUC__)
131138 log << type_name<decltype (s)>() << " \n " ;
139+ #endif
132140
133141 // use the slice to create a new valarray
134142 std::valarray<int > result = v[s];
0 commit comments