-
-
Notifications
You must be signed in to change notification settings - Fork 606
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bugzilla 6082 - Constructors of templated types should be callabl…
…e via IFTI
- Loading branch information
Showing
8 changed files
with
156 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Constructor calls can implicitly instantiate struct templates | ||
|
||
Implicit Function Template Instantiation now also works with struct constructors. | ||
Example: | ||
--- | ||
struct Tuple(T...) | ||
{ | ||
T fields; | ||
this(T t) { this.fields = t; } | ||
} | ||
|
||
static assert(Tuple(1, 2, 3).fields[0] == 1); | ||
--- | ||
|
||
This removes the need for helper functions such as: | ||
|
||
--- | ||
auto tuple(T...)(T args) => Tuple!T(args); | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Template parameter deduction for constructors | ||
// dlang.org/dips/40 | ||
|
||
////////////////////////////////////////// | ||
// Basic succes case | ||
struct Dip40(T) | ||
{ | ||
T x; | ||
this(T x) { this.x = x; } | ||
} | ||
|
||
static assert (Dip40(30).x == 30); | ||
static assert ("a".Dip40.x == "a"); | ||
|
||
////////////////////////////////////////// | ||
// Variadic template arguments | ||
struct Tuple(T...) | ||
{ | ||
T fields; | ||
this(T t) { this.fields = t; } | ||
} | ||
|
||
static assert (Tuple(1, 2, 3).fields[0] == 1); | ||
static assert(is(typeof(Tuple('a', "b")) == Tuple!(char, string))); | ||
|
||
////////////////////////////////////////// | ||
// Constructor is required for now | ||
struct CtorLess(T) | ||
{ | ||
T x; | ||
} | ||
static assert(!is(typeof(CtorLess('a')))); | ||
|
||
////////////////////////////////////////// | ||
// Partial instantiation not supported | ||
struct Pair(T, U) | ||
{ | ||
T x; | ||
U y; | ||
this(T x, U y) { this.x = x; this.y = y; } | ||
} | ||
static assert(!is(typeof(Pair!char('a', "b")))); | ||
|
||
////////////////////////////////////////// | ||
// Ambiguity errors are checked | ||
struct Ambig(T) | ||
{ | ||
T x; | ||
this(int x, int y) { this.x = x; } | ||
this(T x) { this.x = x; } | ||
} | ||
static assert(!is(typeof(Ambig(0)))); | ||
|
||
////////////////////////////////////////// |