【发布时间】:2019-04-26 22:43:49
【问题描述】:
#include <type_traits>
int main()
{
int arr[1] = { 6 };
auto& ref1 = arr[0];
static_assert( std::is_same_v<decltype( ref1 ), int&> ); //ok
auto& [ ref2 ] = arr;
static_assert( std::is_same_v<decltype( ref2 ), int> ); //ok
static_assert( std::is_same_v<decltype( ref2 ), int&> ); //error
}
在该示例中,标识符 ref1 和 ref2 之间的区别是什么?据我了解,结构绑定中的ref2也有引用类型,但是为什么decltype为它指明了非引用类型呢?
【问题讨论】:
-
this 回答你的问题了吗?
标签: c++ c++17 auto decltype type-deduction