Why can’t I use alias from a base class in a derived class with templates?

Unqualified lookup does not look in dependent base classes in class templates. So here: template <typename Socket> class StartSession : public Step<Session<Socket> > { protected: Session_ptr m_session; // <== unqualified name lookup on Session_ptr // … }; Step<Session<Socket>> is a dependent base class of StartSession<Socket>. In order to lookup there, you’ll have to do qualified … Read more

Returning constrained generics from functions and methods

I think the key to understanding what is going on here is distinguishing between things that are determined dynamically at runtime, and things that are determined statically at compile time. It doesn’t help that, in most languages like Java, protocols (or interfaces) are all about getting polymorphic behavior at run time, whereas in Swift, protocols … Read more

How do I add different types conforming to a protocol with an associated type to a collection?

Protocols with type aliases cannot be used this way. Swift doesn’t have a way to talk directly about meta-types like ValidationRule or Array. You can only deal with instantiations like ValidationRule where… or Array<String>. With typealiases, there’s no way to get there directly. So we have to get there indirectly with type erasure. Swift has … Read more