In the following code, I am using a template function and type traits to distinguish between an integer type (else case) and array type. I would expect the output to be int
and array
respectively, instead I get int
int
with the two calls that instantiates the template functions respectively with an int type and an array type:
Why is that?
#include <iostream>
#include <array>
template <typename T>
inline static void constexpr SetCoordinates()
{
if (std::is_array<T>::value)
std::cout<<"array\n";
else
std::cout<<"int\n";
}
int main()
{
int a = 6;
std::array<int, 4> arr = {1,2,3,4};
SetCoordinates<decltype(a)>();
SetCoordinates<decltype(arr)>();
return 0;
}
Aucun commentaire:
Enregistrer un commentaire