100DaysOfGameDev: Day 35

More templates! I cannot explain why, but it's a fundamentally harder concept for me to grasp and understand, than anything else in the programming world. You can achieve similar behavior to templates using char* and interpreting bytes, or using macros with less type safety. Or you can have a single base class to represent them all. Idk, someone may read this and be disgusted with what I am saying, because it is disgusting. However, those concepts are simpler and easier to understand what to expect from them. With templates ( generics ), however, I do not know which part is handled by the compiler, which part is not, or how the compiler processes all that template soup. There were examples, that used three template parameters and I do not understand how the compiler is enforcing correspondence between them, or otherwise, it does not at all.

/* Seems fine, we declare List with two template parameters T and Allocator. */
template<typename T, typename Allocator>
class List;

template<typename T>
class Link {
    /* Okay this is so weird. The concept of the link is to hold the value of a list, therefore, why the hell on earth does the List here have parameter U and not T. Doesn't that mean that we can have a case where a list of ints can have links that hold strings, why would we need that? */
    template<typename U, typename A>
        friend class List;
    T val;
    Link* succ;
    Link* prev;
};

templates<typename T, typename Allocator>
class List {
    // ...
};

So many questions with this example in this book. However, this is it for today, see you tomorrow!