Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,19 @@
class T {
override string toString() { return "I'm the instance of T"; }
T duplicate() { return new T; }
}
class S : T {
override string toString() { return "I'm the instance of S"; }
override T duplicate() { return new S; }
}
void main () {
import std.stdio;
T orig = new S;
T copy = orig.duplicate();
writeln(orig);
writeln(copy);
}

View file

@ -0,0 +1,46 @@
class T {
this(T t = null) {} // Constructor that will be used for copying.
override string toString() { return "I'm the instance of T"; }
T duplicate() { return new T(this); }
bool custom(char c) { return false; }
}
class S : T {
char[] str;
this(S s = null) {
super(s);
if (s is null)
str = ['1', '2', '3']; // All newly created will get that.
else
str = s.str.dup; // Do the deep-copy.
}
override string toString() {
return "I'm the instance of S p: " ~ str.idup;
}
override T duplicate() { return new S(this); }
// Additional procedure, just to test deep-copy.
override bool custom(char c) {
if (str !is null)
str[0] = c;
return str is null;
}
}
void main () {
import std.stdio;
T orig = new S;
orig.custom('X');
T copy = orig.duplicate();
orig.custom('Y');
orig.writeln;
copy.writeln; // Should have 'X' at the beginning.
}