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

Abierto
#500 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
62/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
cpp
Área
tooling

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
C++
Estrellas
12
Forks
4
Merge medio
1 d 11 h
PR fusionados (30 d)
15

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de jbcoe/cc-protocol

Todos los issues de jbcoe/cc-protocol

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.