Я хотел бы знать, запрещает ли стандарт вычет аргумента класса (CTAD) для заполнителя с зависимым элементом без ареста в объявлении, подобном этому: < /p>
auto d1 = D{{1, 2}};
gcc 15.1 и clang 20.1.0 (с -std = c ++ 20 или -std = c ++ 23) не скомпилируется. The only thing I’ve found on cppreference.com is that
brace elision is not considered for any aggregate element that
has a dependent non-array type
, which would explain d2. Тем не менее, пример из этого блога успешно компилируется, даже хотя они явно не указывают тип последнего инициализатора {5, 6} –, так почему
auto d1 = D{{1, 2}};
не скомпилируется, но
A1 a1{{1,2,3}, 4, {5, 6}};< /code> < /p>
Успех? Определите список параметров T₁, T₂,…, Tₙ кандидата в совокупный вычет следующим образом: < /p>
Если eᵢ является массивом, а argᵢ является листом Bred init, tᵢ-это rvalue wor the decled of eᵢ.
. />
...
< /blockquote>
< /blockquote>
logbolt link < /p>
#include
template
struct B
{
T t1;
T t2;
// aggregate deduction candidate:
// template
// B(T, T) -> B;
};
template
struct D
{
B b;
// aggregate deduction candidate:
// template
// D(B) -> D;
};
// example from https://oleksandrkvl.github.io/2021/04/ ... #ctad-aggr
// example begin
template
struct Pair
{
T first;
U second;
// aggregate deduction candidate:
// template
// Pair(T, U>) -> Pair;
};
template
struct A1
{
T data[N];
T oneMore;
Pair p;
// aggregate deduction candidate:
// template
// A1(T(&&)[N], T, Pair) -> A1;
};
// example end
int main()
{
// auto d1 = D{{1, 2}}; // error: is this declaration legal?
// auto d2 = D{1, 2}; // error: OK, I expected this to be illegal because of brace elision
auto d3 = D{B{1, 2}}; // ok
static_assert(std::is_same_v);
// example from https://oleksandrkvl.github.io/2021/04/ ... #ctad-aggr
// example begin
// A1::data is an array of dependent bound and A1::p is a dependent type, thus,
// no brace elision for them
A1 a1{{1,2,3}, 4, {5, 6}}; // A1
// example end
static_assert(std::is_same_v);
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... ay-element
Почему CTAD терпит неудачу в совокупности с зависимым элементом, не связанным с аразовым элементом? ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Mypy терпит неудачу с ожидаемым типом «Type[T]», вместо этого получен «UnionType»
Anonymous » » в форуме Python - 0 Ответы
- 67 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Мой файл .py работает отлично, но когда я превращаю его в .exe, он терпит неудачу.
Anonymous » » в форуме Python - 0 Ответы
- 66 Просмотры
-
Последнее сообщение Anonymous
-