I am new to template meta programming and was trying to create a program that would find if a parameter pack has consecutive same type names. For example <int, int>
, <int, char, char>
would return true and <int,char>
and <int, char, int>
would not.
I managed to write this piece of code but it seems to be comparing each value of parameter pack with itself. I am just looking for a way to iterate through the values of parameter pack to compare with it's consecutive element.
template<typename T, typename U>
struct sameTypename{
enum {value = false};
};
template<typename T>
struct sameTypename<T, T>{
enum {value = true};
};
template <typename T, typename ...args>
struct consTypename{
enum {value = (sameTypename<consTypename<args...>, consTypename<args...>>::value)};
};
template <typename T>
struct consTypename<T, T>{
enum {value = true};
};
template <typename T>
struct consTypename<T>{
enum {value = false};
};
sameTypename<consTypename<args...>, consTypename<args...>>::value
is going to do? – Detached