Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indentation style for classes and class templates #1576

Closed
tkoeppe opened this issue Mar 25, 2017 · 2 comments
Closed

Indentation style for classes and class templates #1576

tkoeppe opened this issue Mar 25, 2017 · 2 comments

Comments

@tkoeppe
Copy link
Contributor

tkoeppe commented Mar 25, 2017

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.

@tkoeppe
Copy link
Contributor Author

tkoeppe commented Mar 25, 2017

Found one candidate for review: [time], everything in namespace chrono.

Found another candidate: [basic.string]

tkoeppe added a commit that referenced this issue Mar 26, 2017
* Remove unnecessary linebreaks from function signatures.
* Adjust class formatting according to #1576.
@jensmaurer
Copy link
Member

Latest decisions are in #1754.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants