(git HEAD) std.datetime spewing deprecation messages
Artur Skawina via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jun 5 18:28:43 PDT 2014
On 06/06/14 02:34, Jonathan M Davis via Digitalmars-d wrote:
> On Thu, 05 Jun 2014 18:18:33 -0400
> Steven Schveighoffer via Digitalmars-d <digitalmars-d at puremagic.com>
> wrote:
>
>> On Thu, 05 Jun 2014 18:06:01 -0400, monarch_dodra
>> <monarchdodra at gmail.com> wrote:
>>
>>> On Thursday, 5 June 2014 at 08:49:18 UTC, Jonathan M Davis via
>>> Digitalmars-d
>>>> long days;
>>>> int seconds;
>>>> short msecs;
>>>> d.split!("days", "seconds", "msecs")(&days, &seconds, &msecs);
>>>
>>> Please don't use pass-by-pointer in D APIs. It makes it a real
>>> *nightmare* to ever use the code in a safe context.
>>
>> This is similar to getopt and readf. I think it's a good way to show
>> that a reference is being passed.
>
> And like with them, it's impossible to use ref for this, because you can't use
> ref with variadic template arguments. So, there isn't even any debate as to
> whether ref or pointers would be nicer. Since it's _impossible_ to use
> ref for this, there's no choice. Anyone who doesn't want to use
struct D {
// In real code these methods would do the work:
long days() @property { return 2012; }
int seconds() @property { return 34; }
short msecs() @property { return 567; }
template split(NAMES...) {
auto split(REFS...)(ref REFS refs) {
foreach (I, N; NAMES)
refs[I] = mixin(N);
}
}
}
void main() {
long days;
int seconds;
short msecs;
auto d = D();
d.split!("days", "seconds", "msecs")(days, seconds, msecs);
import std.stdio;
writeln(days, seconds, msecs);
}
But this would be much worse than the return-by-pointer solution.
artur
More information about the Digitalmars-d
mailing list