Explore composing an interface from several structs

Aperta
#511 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
15/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
backend

Direzione di ricerca

The question is whether protocol should accept an interface with base classes, rejecting it or counting inherited members, and how to settle that in the design. Start from the open questions on public and virtual bases and on duplicate signatures, and from the protocol template and the #390 and #98 threads it cites. Done means a decision on composition and narrowing, and a diagnostic for protocol<Both> if the chosen direction rejects base classes.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Can one protocol require the member functions of several interface structs, the way a class can derive from several abstract bases? Today the only way is to write a new struct that repeats every member.

struct Drawable { void draw() const; };
struct Printable { void print() const; };

Two spellings:

  1. Inheritance on the interface. struct Both : Drawable, Printable {}; and protocol<Both>. This is the sketch in #390. protocol keeps its <I, Allocator> shape, and the composed interface has a name.
  2. Several interface arguments. protocol<Drawable, Printable>, as duck does (#98). The allocator is the second template parameter, so a list of interfaces has nowhere to go, and jbcoe was against this in #98 as inconsistent with polymorphic.

Spelling 1 compiles today and does the wrong thing. Inherited members are ignored without a diagnostic: protocol<Both> has neither draw nor print, and every class type conforms to Both. Whatever is decided here, that should stop. Either reject an interface that has base classes, or count their members.

Questions:

  • Is it worth having? Repeating the members in one struct works now. Composition saves the repetition and keeps the pieces in step.
  • Which members count? Public bases only? If two bases declare the same signature, is that one requirement, or an error as it would be for name lookup? What about virtual and repeated bases?
  • Does narrowing come with it? #390 wants a protocol_view<Drawable> from a protocol<Both>. Narrowing only to declared bases needs a vtable per base rather than per subset of members, so it may avoid the growth described in #98. The outline defers narrowing (#88), so composition could come first without it.

Suggested first step: reject an interface with base classes, so that the current behaviour cannot be relied on while this is decided.

Lingua principale
C++
Stelle
12
Fork
4
Merge medio
1g 11h
PR unite (30g)
15

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jbcoe/cc-protocol

Tutte le issue di jbcoe/cc-protocol

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.