Decide one rule for which `protocol` operations are members and which are hidden friends

オープン
#453 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
リファクタリング
明瞭さ
説明が足りない
活発さ
活発
技術スタック
cpp

調査の方向性

Start with DRAFT.md's "Reserved member names" section, then inspect #449's reserved_member_names and its guard test. Compare the four proposed rules and the related discussion in #194 before choosing one. Done means the rule is decided, DRAFT.md and the P3019 divergence are updated, and the related code and guard test match the choice.

索引モデルが issue の本文から書いたものです。

説明

From the review of #449: https://github.com/jbcoe/cc-protocol/pull/449#issuecomment-5751922382

protocol follows polymorphic for some operations and not for others:

Operation polymorphic protocol
swap member and hidden friend member and hidden friend
get_allocator member member
allocator_type member type member type
valueless_after_move member hidden friend (#394, #395)
target_type, protocol_cast none hidden friends (#314, #306)

Every member reserves a name an interface cannot use (#318, #449). valueless_after_move became a hidden friend to reserve one name fewer. swap stays a member because p.swap(pp) and swap(p, pp) should both work and agree, as on polymorphic. The parity argument that keeps swap a member would also have kept valueless_after_move one, and the reserved-name argument that moved valueless_after_move would also move swap, which already has a hidden-friend form.

jbcoe's replies after #449 merged (first, second) add two points. valueless_after_move is unusual enough that users bring no member-call expectation from polymorphic, unlike swap. And a hidden friend leaves the name free for the interface, which is a hazard for this name in particular:

struct I {
  bool valueless_after_move() const;
};

xyz::protocol<I> p(std::in_place_type<T>);
auto q = std::move(p);
valueless_after_move(p);   // hidden friend: true
p.valueless_after_move();  // generated member: calls through a valueless protocol, undefined behaviour

The interface is accepted today, because reserved_member_names holds only the three member names. No interface is likely to need the name, so rejecting it costs little. target_type and protocol_cast are hidden friends too, but an interface member with one of those names is no more dangerous than any other forwarded call.

Options:

  1. Parity with polymorphic. Make valueless_after_move a member again and reserve it. Code written against polymorphic works unchanged with protocol; four reserved names.
  2. Fewest reserved names. Drop the member swap and make get_allocator a hidden friend. Only allocator_type stays reserved, which uses_allocator needs.
  3. Keep today's split and state the rule: an operation polymorphic offers in a hidden-friend form, or that protocol adds, is a hidden friend only; one polymorphic offers only as a member keeps the member. By that rule valueless_after_move is the exception and needs its own sentence in DRAFT.md.
  4. Keep today's split and reserve valueless_after_move anyway. reserved_member_names gains the name, and the guard test ReservedMemberNamesAreThePublicMembersOfProtocol allows that one extra. DRAFT.md's sentence that a hidden friend "reserves no name" changes to say why this one is reserved. The rejection is per interface, so it applies to the views too.

Options 1 and 4 remove the hazard; 2 and 3 keep it.

Whichever is chosen, DRAFT.md's "Reserved member names" has to give the rule, and the divergence from P3019 belongs with the others in #194. #449's reserved_member_names and its guard test follow the choice mechanically.

主要言語
C++
スター
12
フォーク
4
平均マージ
1日 11時間
マージ済み PR(30日)
15

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

jbcoe/cc-protocol のほかの issue

jbcoe/cc-protocol の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。