Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Delegates/D/delegates-1.d
Normal file
24
Task/Delegates/D/delegates-1.d
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
class Delegator {
|
||||
string delegate() hasDelegate;
|
||||
|
||||
string operation() {
|
||||
if (hasDelegate is null)
|
||||
return "Default implementation";
|
||||
return hasDelegate();
|
||||
}
|
||||
|
||||
typeof(this) setDg(string delegate() dg) {
|
||||
hasDelegate = dg;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
import std.stdio;
|
||||
auto dr = new Delegator;
|
||||
string delegate() thing = () => "Delegate implementation";
|
||||
|
||||
writeln(dr.operation());
|
||||
writeln(dr.operation());
|
||||
writeln(dr.setDg(thing).operation());
|
||||
}
|
||||
29
Task/Delegates/D/delegates-2.d
Normal file
29
Task/Delegates/D/delegates-2.d
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import tango.io.Stdout;
|
||||
|
||||
class Delegator
|
||||
{
|
||||
private char[] delegate() hasDelegate;
|
||||
public:
|
||||
char[] operation() {
|
||||
if (hasDelegate is null)
|
||||
return "default implementation";
|
||||
return hasDelegate();
|
||||
}
|
||||
|
||||
typeof(this) setDg(char[] delegate() dg)
|
||||
{
|
||||
hasDelegate = dg;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
int main(char[][] args)
|
||||
{
|
||||
auto dr = new Delegator();
|
||||
auto thing = delegate char[]() { return "delegate implementation"; };
|
||||
|
||||
Stdout ( dr.operation ).newline;
|
||||
Stdout ( dr.operation ).newline;
|
||||
Stdout ( dr.setDg(thing).operation ).newline;
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue