-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #451 from andreasfertig/fixIssue425
Fixed #425: Show the correct reference type for structured bindings.
- Loading branch information
Showing
17 changed files
with
291 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <utility> | ||
|
||
int main() | ||
{ | ||
std::pair<int, char> p; | ||
auto [a, b] = p; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <utility> | ||
|
||
int main() | ||
{ | ||
std::pair<int, char> p = std::pair<int, char>(); | ||
std::pair<int, char> __p6 = std::pair<int, char>(p); | ||
int && a = std::get<0UL>(static_cast<std::pair<int, char> &&>(__p6)); | ||
char && b = std::get<1UL>(static_cast<std::pair<int, char> &&>(__p6)); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Source: https://en.cppreference.com/w/cpp/language/structured_binding | ||
#include <tuple> | ||
|
||
float x{}; | ||
char y{}; | ||
int z{}; | ||
|
||
std::tuple<float&,char&&,int> tpl(x,std::move(y),z); | ||
const auto& [a,b,c] = tpl; | ||
// a names a structured binding that refers to x; decltype(a) is float& | ||
// b names a structured binding that refers to y; decltype(b) is char&& | ||
// c names a structured binding that refers to the 3rd element of tpl; decltype(c) is const int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Source: https://en.cppreference.com/w/cpp/language/structured_binding | ||
#include <tuple> | ||
|
||
float x = {}; | ||
|
||
char y = {}; | ||
|
||
int z = {}; | ||
|
||
|
||
std::tuple<float &, char &&, int> tpl = std::tuple<float &, char &&, int>(x, std::move(y), z); | ||
|
||
const std::tuple<float &, char &&, int> & __tpl9 = tpl; | ||
float & a = std::get<0UL>(__tpl9); | ||
char & b = std::get<1UL>(__tpl9); | ||
const int & c = std::get<2UL>(__tpl9); | ||
|
||
// a names a structured binding that refers to x; decltype(a) is float& | ||
// b names a structured binding that refers to y; decltype(b) is char&& | ||
// c names a structured binding that refers to the 3rd element of tpl; decltype(c) is const int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <tuple> | ||
|
||
auto tup = std::tuple<int, int>{2, 5}; | ||
auto [a1, b1] = tup; | ||
|
||
|
||
int i = 5; | ||
auto tup2 = std::tuple<int, int&>{2, i}; | ||
auto [a2, b2] = tup2; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <tuple> | ||
|
||
std::tuple<int, int> tup = std::tuple<int, int>{2, 5}; | ||
|
||
std::tuple<int, int> __tup4 = std::tuple<int, int>(tup); | ||
int && a1 = std::get<0UL>(static_cast<std::tuple<int, int> &&>(__tup4)); | ||
int && b1 = std::get<1UL>(static_cast<std::tuple<int, int> &&>(__tup4)); | ||
|
||
|
||
|
||
int i = 5; | ||
|
||
std::tuple<int, int &> tup2 = std::tuple<int, int &>{2, i}; | ||
|
||
std::tuple<int, int &> __tup29 = std::tuple<int, int &>(tup2); | ||
int && a2 = std::get<0UL>(static_cast<std::tuple<int, int &> &&>(__tup29)); | ||
int & b2 = std::get<1UL>(static_cast<std::tuple<int, int &> &&>(__tup29)); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
|
||
// p1 | ||
// cv := denote the cv-qualifiers in the decl-specifier-seq | ||
// S := consist of the storage-class-specifiers of the decl-specifier-seq (if any) | ||
// | ||
// 1) a variable with a unique name e is introduced. | ||
// If the assignment-expression in the initializer has array type A and no ref-qualifier is present, e is defined by: | ||
// | ||
// attribute-specifier-seq_{opt} S cv A e ; | ||
// | ||
// otherwise e is defined as-if by: | ||
// | ||
// attribute-specifier-seq_{opt} decl-specifier-seq ref-qualifier_{opt} e initializer ; | ||
// | ||
// The type of the id-expression e is called E. | ||
// | ||
// Note: E is never a reference type | ||
// | ||
// | ||
// -- tuple -- | ||
// Let i be an index of type std::size_t corresponding to vi | ||
// either: | ||
// e.get<i>() | ||
// get<i>(e) | ||
// | ||
// In either case, | ||
// - e is an lvalue if the type of the entity e is an lvalue reference and | ||
// - an xvalue otherwise. | ||
// | ||
// -> auto& [a ,b ] -> e := lvalue | ||
// -> auto [a ,b ] -> e := xvalue | ||
// | ||
// T_i := std::tuple_element<i, E>::type | ||
// U_i := either | ||
// - T_i&: if the initializer is an lvalue, | ||
// - T_i&&: an rvalue reference otherwise, | ||
// | ||
// variables are introduced with unique names r_i as follows: | ||
// | ||
// S U_i r_i = initializer ; | ||
// | ||
// Each vi is the name of an lvalue of type Ti that refers to the object bound to ri; the referenced type is Ti. | ||
// | ||
|
||
|
||
// The lvalue is a bit-field if that member is a bit-field. [Example: | ||
// struct S { int x1 : 2; volatile double y1; }; | ||
// S f(); | ||
// const auto [ x, y ] = f(); | ||
// The type of the id-expression x is “const int”, the type of the id-expression y is “const volatile double”. —end example] | ||
|
||
|
||
// For each identifier, a variable whose type is "reference to std::tuple_element<i, E>::type" is introduced: lvalue reference if its corresponding initializer is an lvalue, rvalue reference otherwise. The initializer for the i-th variable is | ||
// - e.get<i>(), if lookup for the identifier get in the scope of E by class member access lookup finds at least one declaration that is a function template whose first template parameter is a non-type parameter | ||
// - Otherwise, get<i>(e), where get is looked up by argument-dependent lookup only, ignoring non-ADL lookup. | ||
// | ||
// The initializer for the new variable is e.get<i> or get<i>(e). | ||
// Here the overload of get that is called is a rvalue in case we use auto and an lvalue in case we use auto& | ||
|
||
|
||
|
||
#include <cassert> | ||
#include <tuple> | ||
|
||
// https://en.cppreference.com/w/cpp/language/structured_binding | ||
float x{}; | ||
char y{}; | ||
int z{}; | ||
|
||
std::tuple<float&,char&&,int> tpl(x,std::move(y),z); | ||
//auto tpl = std::tuple{x,std::move(y),z}; | ||
auto& [a,b,c] = tpl; | ||
// a names a structured binding that refers to x; decltype(a) is float& | ||
// b names a structured binding that refers to y; decltype(b) is char&& | ||
// c names a structured binding that refers to the 3rd element of tpl; decltype(c) is int | ||
|
||
int main() { | ||
a = 4.5; | ||
c = 5; | ||
|
||
// assert(4.5 == x); | ||
// assert(0 == z); | ||
|
||
// std::cout << a << '\n'; | ||
// std::cout << z << '\n'; | ||
} |
Oops, something went wrong.