On Wednesday, 4 June 2014 at 15:51:58 UTC, John Colvin wrote:
On Wednesday, 4 June 2014 at 14:16:31 UTC, Meta wrote:
On Wednesday, 4 June 2014 at 11:28:52 UTC, Kagamin wrote:
Does one really needs only one component, but not the others?
Maybe it should provide full computed broken form instead of
separate components?
auto d=dur.breakUp;
d.hours; d.minutes; d.seconds;
In some glorious future where we can destructure tuples, you
could do something like this:
(hours, minutes, seconds) = dur.parts;
Assuming hours, minutes and seconds are already declared, you
can do this already
TypeTuple!(hours, minutes, seconds) = dur.parts;
A full working example of the syntax:
import std.typetuple;
import std.typecons;
import std.stdio;
void main()
{
int a,b;
TypeTuple!(a, b) = tuple(5, 8);
assert(a == 5 && b == 8);
}
On Wednesday, 4 June 2014 at 14:16:31 UTC, Meta wrote:
In some glorious future where we can destructure tuples, you
could do something like this:
(hours, minutes, seconds) = dur.parts;
In the most glorious of futures where D supports over-powered
macros, a macro `def` could be defined s.t.
def(hours, minutes, seconds) = dur.parts;
results in
typeof(dur.parts)[0] hours;
typeof(dur.parts)[1] minutes;
typeof(dur.parts)[2] seconds;
TypeTuple!(hours,minutes,seconds) = dur.parts;
Along with a huge number of other possible/desired "language
features" could be made without actually touching the compiler.
Of course, I know macros aren't ever coming, but I'm just sayin'
... :)