Is it guaranteed that template template parameter invoke user provided deduction guides

走远了吗. 提交于 2019-12-08 19:16:20

问题


Consider an example:

#include <type_traits>
#include <string>

template <template <class> class TT> //#1
struct Foo {
   static void foo() {
      static_assert(std::is_same_v<decltype(TT("abc")), TT<std::string>>);
   }
};

template <class T>
struct Bar {
    Bar(T) {}
};

template <class T>
Bar(T) -> Bar<std::string>; //#2

int main() {
    Foo<Bar>::foo();
}

[clang] as well as [gcc] both seem to use user provided deduction guides (#2) when deducing the template parameter of template template parameter (#1). Is it a standard compliant feature?


回答1:


Yes, this is standard compliant.

According to [dcl.type.simple]/2:

A type-specifier of the form typenameoptnested-name-specifieropttemplate-name is a placeholder for a deduced class type ([dcl.type.class.deduct]). The template-name shall name a class template that is not an injected-class-name.

And [temp.param]/3:

A type-parameter whose identifier does not follow an ellipsis defines its identifier to be a typedef-name (if declared without template) or template-name (if declared with template) in the scope of the template declaration.

TT is a type-parameter declared with template, which makes it a template-name and hence a placeholder for a deduced class type. All the usual rules apply just fine.



来源:https://stackoverflow.com/questions/46610383/is-it-guaranteed-that-template-template-parameter-invoke-user-provided-deduction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!