Howard Hinnant wrote:
Maybe something along the lines of:
template <class T, bool = HasNext<T>::value>
struct Last
{
typedef Link<T>::next_type;
};
template <class T>
struct Last<T, false>
{
typedef T next_type;
};
Thanks, but unfortunately, that will only give you the next type in the
list if there is any, or the type itself if there is not. It will not
recursively traverse the whole list until the end. I've tried several
variants that all boil down to something along the lines of:
template <typename T>
struct Last
{
typedef If<HasNext<T>::value, Last<Link<T>::next_type>::type,
T>::type type;
};
using a standard If<bool, typename Ta, typename Tb> template, but this
gives all sorts of compile errors, most of which seem to have to do
with the fact that I use Last<T>::type before I have actually completed
defining it. So more specifically, I am looking for a way around this.
think. To get around that, you can introduce delayed instantiation: