My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
dmd nonstd/traits nonstd/typecons -run test
--------------------
X
43CE60
3.1416
0
core.exception.AssertError@nonstd\typecons.d(328): Base.foo() is not implemented
core.exception.AssertError@nonstd\typecons.d(321): Base.foo(lazy int) is not implemented
core.exception.AssertError@nonstd\typecons.d(335): Base.baz(int[]) is not implemented
*/

import std.stdio;
import std.contracts;
import core.exception;

import std.typetuple;
import nonstd.typecons;
import nonstd.traits;


// For covariant return types
interface X {}
interface Y : X {}


interface Ia { X foo() nothrow; }
interface Ib { Y foo() const; }

class Base : Ia, Ib
{
abstract ref int foo(lazy int);

// overloading *is* desired (cf. "Hijacking")
alias Ia.foo foo;
alias Ib.foo foo;

// non-abstract function
real bar() { return 3.1416; }

// variadic function
abstract int baz(int[] a...) const nothrow;
}

void main()
{
auto bh = new BlackHole!Base;
writeln( bh.foo());
writeln(&bh.foo((assert(0), 1)));
writeln( bh.bar());
writeln( bh.baz(1, 2, 3, 4));

auto wh = new WhiteHole!Base;
try { wh.foo(); } catch (AssertError e) { writeln(e); }
try { wh.foo(1); } catch (AssertError e) { writeln(e); }
wh.bar(); // Base.bar() is not overridden
try { wh.baz(1); } catch (AssertError e) { writeln(e); }
}


Change log

r37 by rsinfu on May 25, 2009   Diff
-
Go to: 
Project members, sign in to write a code review

Older revisions

r36 by rsinfu on May 25, 2009   Diff
revert: removed the (uint i) parameter
r24 by rsinfu on May 24, 2009   Diff
greatly generalized
r18 by rsinfu on May 24, 2009   Diff
small update
All revisions of this file

File info

Size: 1403 bytes, 60 lines
Powered by Google Project Hosting