Constrain `protocol`'s constructors and converting assignment on constructibility of the stored type

Aperta
#500 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à
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
tooling

Direzione di ricerca

Start with the protocol value constructors, in-place constructors and converting assignment, and compare them with the polymorphic constructors, which already constrain on is_constructible_v. Add std::constructible_from constraints to the overloads the issue lists, and check that the converting assignment matches the change in #499. Done when the issue's static_asserts hold and protocol<MI> rejects MoveOnly at overload resolution instead of failing inside construct_at.

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

Descrizione

protocol's value, in-place and converting-assignment overloads check conformance and the interface's special members, but not that the stored type can be constructed from the arguments. Type traits report them as available, and calling one fails inside the allocator:

struct I { int value() const; };
struct MI {
  MI() = default;
  MI(MI&&) = default;
  MI(const MI&) = delete;
  int value() const;
};
struct MoveOnly { std::unique_ptr<int> p; int value() const; };
struct Small { int v; int value() const; };

static_assert(std::is_constructible_v<xyz::protocol<MI>, MoveOnly&>);
static_assert(std::is_assignable_v<xyz::protocol<MI>&, MoveOnly&>);
static_assert(std::is_constructible_v<xyz::protocol<I>,
                                      std::in_place_type_t<Small>, std::string>);

MoveOnly m;
xyz::protocol<MI> p(m);  // error: no matching function for call to construct_at

Generic code that branches on these traits gets a hard error instead of the other branch.

polymorphic constrains its value constructor on is_constructible_v<UU, U> and its in-place constructors on is_constructible_v<U, Ts...>. Proposal: add std::constructible_from<TNorm, T> to the value constructors and the converting assignment (#499), and std::constructible_from<T, Args...> (plus the initializer_list form) to the in-place constructors.

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.