C++11 template alias as template template argument leads to different type?

本小妞迷上赌 提交于 2019-11-29 13:27:23

The current standard doesn't say so, but the intention is that y and z have the same type. There is an open Core Working Group issue for this: http://wg21.cmeerw.net/cwg/issue1286

I think you are confusing a type and a template (or a template alias). You have Y, which is one template and Z, which is another one. If you think that Y == Z, you are wrong. Only if you turn them into types, those types are the same, e.g. Y<int> is the same type as Z<int>. In your example:

template<class T> struct X { };

template<class> struct Y { };
template<class T> using Z = Y<T>;

int main() {
  X<Y<int>> y;
  X<Z<int>> z;
  z = y; // works
}

In your original code you referred to them with X<Y> and X<Z>, but as Y is not the same as Z, so are X<Y> and X<Z> different types.

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