www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Tuple expansion already?

reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
For once, let's take something from C++. ;) Structured bindings are 
accepted for C++:

   https://isocpp.org/blog/2015

Assuming that f() returns a tuple,

   auto {x,y,z} = f();

will be the same as

   auto t = f();
   auto x = get<1>(t);
   auto y = get<2>(t);
   auto z = get<3>(t);

Ali
Nov 17 2015
next sibling parent reply rsw0x <anonymous anonymous.com> writes:
On Wednesday, 18 November 2015 at 02:19:34 UTC, Ali Çehreli wrote:
 For once, let's take something from C++. ;) Structured bindings 
 are accepted for C++:

   https://isocpp.org/blog/2015

 Assuming that f() returns a tuple,

   auto {x,y,z} = f();

 will be the same as

   auto t = f();
   auto x = get<1>(t);
   auto y = get<2>(t);
   auto z = get<3>(t);

 Ali
Kenji already wrote(and implemented IIRC) a DIP for this, I don't think it was ever approved. http://wiki.dlang.org/DIP32 I wish D had better Tuple handling at the language level.
Nov 17 2015
parent deadalnix <deadalnix gmail.com> writes:
On Wednesday, 18 November 2015 at 02:21:04 UTC, rsw0x wrote:
 On Wednesday, 18 November 2015 at 02:19:34 UTC, Ali Çehreli 
 wrote:
 For once, let's take something from C++. ;) Structured 
 bindings are accepted for C++:

   https://isocpp.org/blog/2015

 Assuming that f() returns a tuple,

   auto {x,y,z} = f();

 will be the same as

   auto t = f();
   auto x = get<1>(t);
   auto y = get<2>(t);
   auto z = get<3>(t);

 Ali
Kenji already wrote(and implemented IIRC) a DIP for this, I don't think it was ever approved. http://wiki.dlang.org/DIP32 I wish D had better Tuple handling at the language level.
I wish as well, but we have a lot on the drawing board right now, I don'tt hink this is the time for that. There have been proposal that are better than Kenji. Grammatically, Kenji's proposal have some serious problems, { is already the start of a delegate, a block statement, a struct literal, and I'm not sure what else, but too much.
Nov 17 2015
prev sibling next sibling parent Jakob Ovrum <jakobovrum gmail.com> writes:
On Wednesday, 18 November 2015 at 02:19:34 UTC, Ali Çehreli wrote:
 For once, let's take something from C++. ;) Structured bindings 
 are accepted for C++:

   https://isocpp.org/blog/2015

 Assuming that f() returns a tuple,

   auto {x,y,z} = f();

 will be the same as

   auto t = f();
   auto x = get<1>(t);
   auto y = get<2>(t);
   auto z = get<3>(t);

 Ali
Relevant: https://github.com/D-Programming-Language/dmd/pull/341
Nov 17 2015
prev sibling next sibling parent Meta <jared771 gmail.com> writes:
On Wednesday, 18 November 2015 at 02:19:34 UTC, Ali Çehreli wrote:
 For once, let's take something from C++. ;) Structured bindings 
 are accepted for C++:

   https://isocpp.org/blog/2015

 Assuming that f() returns a tuple,

   auto {x,y,z} = f();

 will be the same as

   auto t = f();
   auto x = get<1>(t);
   auto y = get<2>(t);
   auto z = get<3>(t);

 Ali
100x yes. Also dedicated tuple syntax and multiple return types like { } writeln("i = ", i, ", s = ", s);
Nov 17 2015
prev sibling parent reply Brad Anderson <eco gnuk.net> writes:
On Wednesday, 18 November 2015 at 02:19:34 UTC, Ali Çehreli wrote:
 For once, let's take something from C++. ;) Structured bindings 
 are accepted for C++:

   https://isocpp.org/blog/2015

 Assuming that f() returns a tuple,

   auto {x,y,z} = f();

 will be the same as

   auto t = f();
   auto x = get<1>(t);
   auto y = get<2>(t);
   auto z = get<3>(t);

 Ali
I feel like some of the competitive advantage of D is falling away from us with some of the recent C++ developments like this this. Stackless resumable functions is another thing that comes to mind. As does the Core Guidelines Support Library/static analysis pair (though I suspect it'll never be quite as foolproof as Safe D). We can't even do the equivalent of std::tie[1] in D as a workaround for tuple expansion because there are no ref typed Tuples (unless something changed from when I last looked). http://en.cppreference.com/w/cpp/utility/tuple/tie
Nov 17 2015
parent thedeemon <dlang thedeemon.com> writes:
On Wednesday, 18 November 2015 at 04:31:08 UTC, Brad Anderson 
wrote:

 We can't even do the equivalent of std::tie[1] in D as a 
 workaround for tuple expansion because there are no ref typed 
 Tuples (unless something changed from when I last looked).
Several implementations here: http://forum.dlang.org/thread/ubrngkdmyduepmfkhefp forum.dlang.org
Nov 18 2015