如何检查名称是 C++17 中的别名还是引用?

How to check whether a name is an alias or a reference in C++17?

来自cppref

Like a reference, a structured binding is an alias to an existing object. Unlike a reference, the type of a structured binding does not have to be a reference type.

例如:

int a[2] = { 1, 2 };
auto [x, y] = a;

xy 是别名而不是引用。我的问题:

如何实现类似is_alias_v<decltype(x)>的类型检查功能?

我不相信这样的事情是可能的。

幸运的是,永远不需要它。

使用 x 就好像它是美味多汁的 int,无论其来源如何。因为,嗯,就是这样!

另外不要忘记 xy 不是别名或引用 a 的元素,而是 "invisible" 副本。

别名可以是类型别名(例如 using Id = int)或别名模板。

是什么意思

structured binding is an alias to an existing object

[x, y] 作为一个整体是两个整数数组(在本例中)的别名(新名称)。与x的类型名称无关。

如果我们有一些类型别名 using Id = int,则知道 Id 是否是 int 的类型特征将是 std::is_same_t<Id, int>。我不知道如何实现泛型 is_alias_t<Id>.