I want to check if two types are of the same template. As an example I want the following snippet of code to return true
because both objects are vectors despite the inner elements being of different types.
It's important that the check is made at compile time (that's why the function is constexpr).
#include <iostream>
#include <type_traits>
#include <vector>
template <typename Container1, typename Container2> constexpr bool CheckTypes(Container1 c1, Container2 c2)
{
return std::is_same<Container1,Container2>::value;
}
int main()
{
std::vector<int> v1(100,0);
std::vector<double> v2(100,0);
std::cout << CheckTypes(v1,v2);
}
sizeof
, but I'm not sure how elegant of a solution that would be. – Zeidmanstd::vector
as an example, but their questions is more general than that: "I want to check if two types are of the same template". – Contredanse