1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <array>
#include <iostream>
#include <string_view>
template <typename T> constexpr auto type_name()
{
std::string_view name, prefix, suffix;
name = __FUNCSIG__;
prefix = "auto __cdecl type_name<";
suffix = ">(void)";
name.remove_prefix(prefix.size());
name.remove_suffix(suffix.size());
return name;
}
int main()
{
std::array const arr1 {3, 1, 4};
std::cout << "\nstd::array const arr1 {3, 1, 4};\n";
std::cout << "decltype(arr1) is " << type_name<decltype(arr1)>() << '\n';
std::cout << "decltype(arr1[0]) is " << type_name<decltype(arr1[0])>() << '\n';
std::array<const int, 3> arr2 {1, 2, 3};
std::cout << "\nstd::array<const int, 3> arr2 {1, 2, 3}; \n";
std::cout << "decltype(arr2) is " << type_name<decltype(arr2)>() << '\n';
std::cout << "decltype(arr2[0]) is " << type_name<decltype(arr2[0])>() << '\n';
std::array<int, 3> arr5 {1, 2, 3};
std::cout << "\nstd::array<int, 3> arr5 {1, 2, 3}; \n";
std::cout << "decltype(arr5) is " << type_name<decltype(arr5)>() << '\n';
std::cout << "decltype(arr5[0]) is " << type_name<decltype(arr5[0])>() << '\n';
const int arr3[] {4, 5, 6};
std::cout << "\nconst int arr3[] {4, 5, 6}; \n";
std::cout << "decltype(arr3) is " << type_name<decltype(arr3)>() << '\n';
std::cout << "decltype(arr3[0]) is " << type_name<decltype(arr3[0])>() << '\n';
int arr4[] {4, 5, 6};
std::cout << "\nint arr4[] {4, 5, 6}; \n";
std::cout << "decltype(arr4) is " << type_name<decltype(arr4)>() << '\n';
std::cout << "decltype(arr4[0]) is " << type_name<decltype(arr4[0])>() << '\n';
return 0;
}
|