Create an object/Native demonstration: Difference between revisions
Content added Content deleted
(→{{header|Ruby}}: {{works with|Ruby|1.9}} for KeyError) |
(Updated D entry) |
||
Line 13: | Line 13: | ||
TV[TK] standard, current; |
TV[TK] standard, current; |
||
this(TV[TK] default_) pure /*nothrow*/ { |
this(TV[TK] default_) pure /*nothrow*/ @safe { |
||
this.standard = default_; |
this.standard = default_; |
||
this.current = default_.dup; |
this.current = default_.dup; |
||
Line 24: | Line 24: | ||
} |
} |
||
void clear() |
void clear() pure /*nothrow*/ @safe { |
||
current = standard.dup; |
current = standard.dup; |
||
} |
} |
||
Line 31: | Line 31: | ||
void main() { |
void main() { |
||
import std.stdio; |
import std.stdio; |
||
auto d = |
auto d = ["a": 1, "b": 2].DefaultAA!(string, int); |
||
d.writeln; // ["a":1, "b":2] |
|||
d["a"] = 55; d["b"] = 66; |
d["a"] = 55; d["b"] = 66; |
||
d.writeln; // ["a":55, "b":66] |
|||
d.clear |
d.clear; |
||
d.writeln; // ["a":1, "b":2] |
|||
d["a"] = 55; d["b"] = 66; |
d["a"] = 55; d["b"] = 66; |
||
d["a"].writeln; // 55 |
|||
d.remove("a"); |
d.remove("a"); |
||
d.writeln; // ["a":1, "b":66] |
|||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |