Explore composing an interface from several structs

Đang mở
#511 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
15/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C++
Star
12
Fork
4
Merge trung bình
1 ngày 11 giờ
Pull request đã merge (30 ngày)
15

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của jbcoe/cc-protocol

Tất cả issue của jbcoe/cc-protocol

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.