Description
The desired style for class templates is as follows. For short template parameter lists, the class head can be on the same line as template
:
template <typename T> class foo {
public:
int x;
};
The more general form, which is always appropriate, is to separate them onto two lines and indent:
template <typename T>
class foo {
public:
int x;
private:
int y; // exposition only
};
Any access specifiers other than the first one should be preceded by a newline.
Very long member function templates may need to go on three (or more) lines, also suitably indented:
template <typename T>
constexpr return_type<typename made_up_from<T>::type>
some_function(T first, T last);
template <typename T>
constexpr return_type<typename made_up_from<T>::type>
some_other_function( // at most one parameter per line in this style
T first,
T last = T(),
typename iterator_traits<T>::value_type init
= some_default_value, // "=" goes onto the continuation line
bool flag);
Long template parameter lists should be aligned:
template <typename OneType,
typename AnotherType = decay_t<OneType>>
class foo;
We violate both the indent and the newline style in a number of places, usually systematically across an entire subclause. It would be nice to remedy that eventually.
Before embarking on any changes, we should also cross-check with the "namespace std" issue (I forget which one that is) to make sure that we either do or do not enclose the entire class definition in a namespace.