I am trying to write a validation method for a template input, which tests if the input is a std::string, std::vector, or an std::array.
However for the latter I am having an issue as I must provide a constant length for the
type definition.
So when I call std::is_same<T, std::array<uint8_t, container.size()>>::value the compiler of cause gets angry (makes sense container.size() is not static). Is there are way to get around this?
I don't know the size of the container in advance and I will never know it :(
template<typename T> bool valid_container_type(const T& container)
{
(void) container;
if constexpr (std::is_same<T, std::vector<uint8_t>>::value)
{
return true;
}
else if constexpr (std::is_same<T, std::vector<char>>::value)
{
return true;
}
else if constexpr (std::is_same<T, std::array<char, container.size()>>::value)
{
return true;
}
else if constexpr (std::is_same<T, std::array<uint8_t, container.size()>>::value)
{
return true;
}
else if constexpr (std::is_same<T, std::string>::value)
{
return true;
}
return false;
}