Document number: N4225

Ville Voutilainen
2014-10-10

Towards uniform handling of subobjects

Abstract

This paper proposes a generic facility that allows base class aliases, base-from-member idioms, non-static initializers for bases, and more, by introducing new kinds of access-specifiers.

Contents

Introduction

For background, see

This paper attempts to explore a way to do what those facilities are or would be capable of, and more.

Proposed facility

In short, the idea is to allow something like the following:


class B 
{
  B(string);
};

class B2 
{
  B2(vector<int>)
};

class NewMagic 
{
members:
  string foo = "nifty tricks";
  vector<int> bar{1,2,3,4};
public bases:
  B{foo};
  B2{bar};
};


So, to explain it briefly:

Slight alternative

Don't like the idea that a class-head doesn't show you the bases? Not to worry, we could just as well do


class NewMagic : public auto, public auto
{
members:
  string foo = "nifty tricks";
  vector<int> bar{1,2,3,4};
public bases:
  B{foo};
  B2{bar};
};


and require that the bases defined in the class definition match the classes in the class-head.

What is the goal of this proposal?

To put it simply, this is a very preliminary stab at a facility that would seemingly provide solutions for multiple desired facilities in a generic fashion. There are most likely parser issues and other such details to solve, but the first and foremost question is for guidance: