N3955: Group Member Specifiers -- Andrew Tomazos

A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N3955

Date: 2014-02-25

Group Member Specifiers

by Andrew Tomazos

Excerpt:

We propose allowing a space-separated sequence of specifiers to be placed after an access specifier in a class definition. The specifiers so placed are applied to each member declaration in the group following the access-specifier. ...

In class definitions, many times there are contiguous sequences of member declarations that have common specifiers. Under the proposal these common specifiers can be specified once at the start of a group of member declarations, rather than repeated for each member declaration. This can in some cases lead to cleaner, safer, easier-to-write, easier-to-read and easier-to-maintain code.

So instead of:

class foo : public bar
{
public:
    explicit foo(int);
    explicit foo(float);
    explicit foo(double);

protected:
    virtual T f() const override;
    virtual U g() const override;
    virtual V h() const override;
    virtual W i() const override;

private:
    static constexpr int X = 123;
    static constexpr float Y = 42.0f;
    static constexpr double Z = 123.0;
};

You could with group member specifiers equivalently write:

class foo : public bar
{
public explicit:
    foo(int);
    foo(float);
    foo(double);

protected virtual const override:
    T f();
    U g();
    V h();
    W i();

private static constexpr:
    int X = 123;
    float Y = 42.0f;
    double Z = 123.0;
};

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.