What is the type of a
here?
#include <iostream>
#include <tuple>
using namespace std;
int main()
{
float x{};
std::tuple<int> tpl( x );
auto& [ a ] = tpl;
static_assert( std::is_same_v< decltype( a ), int> );
//static_assert( std::is_same_v< decltype( a ), int&> );
}
According to Standard 11.5/3:
[...] Given the type Ti designated by
std::tuple_element<i, E>::type
, variables are introduced with unique names ri of type “reference to Ti” initialized with the initializer (11.6.3), where the reference is an lvalue reference if the initializer is an lvalue and an rvalue reference otherwise. Each vi is the name of an lvalue of type Ti that refers to the object bound to ri; the referenced type is Ti.
Here, i
is 0 for the first element (int) and E
is std::tuple<int>
, so Ti
has type std::tuple_element<0, std::tuple<int>>::type
, i.e. int
. Further ri
(a
in our case) has type "reference to Ti", i.e. lvalue reference int&
, but not just int
.
What is wrong in that quote and why int
type is deduced by both the compilers clang and gcc?