类型别名是否用作功能签名的功能参数类型? [英] Are type aliases used as type of function parameter part of the function signature?

查看:131
本文介绍了类型别名是否用作功能签名的功能参数类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个例子:

#include <iostream>
#include <vector>

template <class, class T>
using alias = T;

template <template <class...> class>
struct tt_wrapper{};

template <class...>
struct t_wrapper{};

struct A {
    template <template <class...> class TT, class T>
    void foo(alias<tt_wrapper<TT>, T>) { std::cout << "A::foo invoked" << std::endl; }
};

struct B: A {
    using A::foo;
    template <class U, class T>
    void foo(alias<t_wrapper<U>, T>) { std::cout << "B::foo invoked" << std::endl; }
};

int main() {
    B b;
    b.foo<std::vector>(int{});
}

根据 [namespace.udecl] / 15


使用声明将基类中的名称带入派生的
类作用域时,派生于
的类中的成员函数和成员函数模板将覆盖和/或隐藏成员函数和成员
函数模板,它们在基类中具有相同的名称,参数类型列表,
cv限定符和ref限定符(如果有)(而不是
而不冲突)

显然,模板参数不应该参与成员函数的隐藏。但是,在我们的示例中,使用别名将模板参数带到签名。不过, c语似乎并没有感觉到别名是函数 parameter-的一部分的感觉。类型列表并声明:

So apparently the template parameters should not be involved in member function hiding. However in our example the template parameters are brought to the signature using alias. Nevertheless clang doesn't seem to share the feeling that alias is part of the function parameter-type-list and claiming:

prog.cc:26:7: error: no matching member function for call to 'foo'
    b.foo<std::vector>(int{});
    ~~^~~~~~~~~~~~~~~~
prog.cc:21:10: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'U'
    void foo(alias<t_wrapper<U>, T>) { std::cout << "B::foo invoked" << std::endl; }
         ^
1 error generated.

我故意忽略了gcc,因为它在隐藏过程中涉及模板参数列表。 lang是正确的吗?

I've intensionally omitted gcc in consideration as it involve template parameter list in the hiding process. Is clang right?

推荐答案

A :: foo B :: foo 具有


  • 相同名称( foo

  • 参数类型列表( T !!!)

  • cv资格(不是 const ,不是易变的)

  • ref限定词(无)

  • same name (foo)
  • parameter-type-list (T !!!)
  • cv-qualification (not const, not volatile)
  • ref-qualifier (None)

模板参数列表。

基类中的方法不是虚拟的,因此隐藏并

The method in base class is not virtual, so hiding and not overriding.

演示 >参数类型列表为 T

Demo of the fact that the parameter-type-list is T.

这篇关于类型别名是否用作功能签名的功能参数类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆