gpt4 book ai didi

c++ - template-name 是推导的上下文吗?

转载 作者:可可西里 更新时间:2023-11-01 18:36:33 24 4
gpt4 key购买 nike

[temp.deduct.type] paragraph 8列出所有推断的上下文,但它似乎不包括 template-name <TT>其中 template-name 指的是类模板和 TT引用模板模板参数。这是推导上下文吗?

如果是,为什么?

如果不是,请考虑以下代码:

template<template<typename> class U, template<typename> class V>
struct foo {};

template<template<typename> class U>
struct foo<U, U> {};

int main() {}

此代码编译 under Clang 7.0.0GCC 8.0.1 ,这意味着编译器认为部分特化比主模板更特化,这意味着 UV在主模板中成功推导出foo<U, U> .这是编译器错误吗?

最佳答案

这一段充满了问题,包括你指出的那个。 Core issue 2328有一个不错的 list :

The presentation style of 17.9.2.5 [temp.deduct.type] paragraph 8 results in a specification that is unclear, needlessly verbose, and incomplete. Specific problems include:

  • What does it mean for P and A to have one of a set of forms? Do they both have to have that form? (That doesn't happen; typically, only P contains template parameters)

  • In the introductory sentence, aren't T, TT, and i supposed to be the names of template parameters rather than template arguments?

  • In T[i], it appears we can deduce i, but not T (T can only be deduced in the form T[<i>integer-constant</i>])

  • What is an integer-constant supposed to be?

  • What is a cv-list?

  • Why can we not deduce const T from T? (Apparently you only get to deduce if both or neither type have a cv-list, whatever a cv-list is.)

  • We have extreme redundancy because, for instance, there is no way to say “in T (T::*)(T), you can deduce any of those Ts, and it's OK if some of the positions don't have a T”. So we have seven (!) forms of that construct, for all cases except the one where none of the three positions contain a T.

  • We have special case rules for pointers to member functions, even though they're not a special case and should be covered by the rule for pointers to members and the rule for functions.

  • We do not allow deducing a template template parameter's value from a template template argument — there is a TT<T> form, a TT<i> form, a <i>template-name</i><T> form, and a <i>template-name</i><i> form, but no TT<TT> form nor <i>template-name</i><TT> form.

看起来编辑设法摆脱了 cv-list ,至少,自提交问题以来。现在只是 cv 。 ( cv-list 有点可笑的错误,因为 [syntax] 说 -list 后缀用于逗号分隔的列表...)

关于c++ - template-name<TT> 是推导的上下文吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48899131/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com