Comparison between two protocol objects

Aperta
#440 2 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
25/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Attiva
Stack tecnologico
cpp

Direzione di ricerca

The issue names no files or tests. Start by reading #439 and #208, then trace the protocol and protocol_view comparison design described here; done means the open semantic, type-identity, mismatch, valueless, conversion, and scope questions have a decided specification.

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

Descrizione

#439 forwards member comparisons with an operand of another type and rejects any comparison on an interface I with an operand of type I. The idiomatic declaration is therefore free to be given a meaning:

struct I {
  bool operator==(const I&) const = default;
  auto operator<=>(const I&) const = default;
};
protocol<I> p(A{}), q(B{});
p == q;

Open questions:

  1. Meaning. Does const I& stand for the conforming type itself? Conformance would then mean C has operator==(const C&) const, and protocol<I> would get operator==(const protocol&) const. Should that apply only to defaulted comparisons, or to user-declared ones as well?
  2. Type identity. The thunk must know that both operands hold the same C before it casts. typeid needs RTTI. The vtable address is cheap but not reliably unique across shared libraries.
  3. Mismatched types. == can return false. <=> could return partial_ordering::unordered (which rules out strong_ordering on the interface), order by type_index (an unspecified order), or throw as Boost.TypeErasure does. std::polymorphic omits comparison for this reason.
  4. Valueless operands. See #208.
  5. protocol_view. Does it compare the referenced objects or the pointers? Should mixed protocol/protocol_view comparison be allowed?
  6. Conversions between interfaces. What does a comparison that names the conforming type do when a protocol converts to another interface?
  7. Scope. Does "own type" stop at comparisons, or extend to members such as void merge(const I&) and I clone() const?

An alternative is a library opt-in (a tag base or trait) in place of rewriting const I&. That works against the design's premise that the interface struct is the whole specification.

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.