template <
typename T,
template <class> class OwnershipPolicy = RefCounted, #1
class ConversionPolicy = DisallowConversion, #2
template <class> class CheckingPolicy = AssertCheck,
template <class> class StoragePolicy = DefaultSPStorage
>
class SmartPtr;
Q1> What is the syntax for the line #1
template <class> class OwnershipPolicy = RefCounted,
why it doesn’t provide a parameter such as follows?
template <class T2> class OwnershipPolicy = RefCounted,
Q2> What is the difference between #1 and #2?
template <class> class OwnershipPolicy = RefCounted,
class ConversionPolicy = DisallowConversion,
Why one of these line have template<class> and the other doesn’t?
template <class> class OwnershipPolicyis a template template argument. I.e.OwnershipPolicyis expected to be a template taking one (and only one) type argument. There’s no name for that argument, because it’s not needed, and you wouldn’t be able to use it for anything anyway.class ConversionPolicyis equivalent totypename ConversionPolicy, i.e. any ordinary type argument.The difference lies in how you use it. For template template arguments, you provide only name of the template, which you can later use to instantiate concrete types. For
typename, you need a concrete type:Worth noting that this idiom is called “policy-based design”.