Type programming game
Adam D. Ruppe
destructionator at gmail.com
Sun Oct 11 01:08:46 UTC 2020
On Saturday, 10 October 2020 at 23:42:46 UTC, Stefan Koch wrote:
> After a few submissions have been made I will post my type
> function, which fulfills this task.
Surely you know by now what I'm going to say... just write a
normal function.
module typegame.solution;
string easy(T...)() {
string result;
// I separate out the display name from the seen name
// since you might pass a.Foo and b.Foo and want it
// differentiated in comparison but both displayed "Foo"
string lastDisplay;
string lastSeen;
int repetitionCount;
void finish() {
if(repetitionCount != 2 && repetitionCount != 3)
return;
if(result.length)
result ~= " ";
if(repetitionCount == 2)
result ~= "double ";
else
result ~= "triple ";
result ~= lastDisplay;
}
foreach(t; T) {
if(t.mangleof == lastSeen) {
repetitionCount++;
} else {
finish();
lastSeen = t.mangleof;
lastDisplay = t.stringof;
repetitionCount = 1;
}
}
finish();
return result;
}
pragma(msg, easy!(int, int, uint, uint, uint));
pragma(msg, easy!(char, char, wchar, dchar, dchar));
More information about the Digitalmars-d
mailing list