Rule A14-5-2 (advisory, design, partially-automated)
Class members that are not dependent on template class parameters should be defined in a separate base class.
Rationale
Having non-dependent members in a class template can lead to unnecessary template instantiations and potential code bloat. It is therefore preferred to move those members to a non-dependent base class so they can be used without any template instantiation.
Example
// $Id: A14-5-2.cpp 323444 2018-06-22 14:38:18Z christof.meerwald $
#include <cstdint>
template<typename T>
class A
{
public:
enum State // Non-Compliant: member doesn’t depend on template parameter
{
State1,
State2
};
State GetState();
};
class B_Base
{
public:
enum State // Compliant: not a member of a class template
{
State1,
State2
};
};
template<typename T>
class B : B_Base
{
public:
State GetState();
};
See also
C++ Core Guidelines [11]: T.62: Place non-dependent class template members in a non-templated base class