Merge pull request #2156 from monarchdodra/stringMixin

Remove gratuitous string mixins
This commit is contained in:
Walter Bright 2014-05-12 02:26:42 -07:00
commit 1778e9fa40

View file

@ -3703,20 +3703,24 @@ unittest
unittest unittest
{ {
string genInput() struct Dummy
{ {
return "@property bool empty() { return _arr.empty; }" ~ mixin template genInput()
"@property auto front() { return _arr.front; }" ~ {
"void popFront() { _arr.popFront(); }" ~ @property bool empty() { return _arr.empty; }
"static assert(isInputRange!(typeof(this)));"; @property auto front() { return _arr.front; }
void popFront() { _arr.popFront(); }
static assert(isInputRange!(typeof(this)));
} }
}
alias genInput = Dummy.genInput;
static struct NormalStruct static struct NormalStruct
{ {
//Disabled to make sure that the takeExactly version is used. //Disabled to make sure that the takeExactly version is used.
@disable this(); @disable this();
this(int[] arr) { _arr = arr; } this(int[] arr) { _arr = arr; }
mixin(genInput()); mixin genInput;
int[] _arr; int[] _arr;
} }
@ -3724,7 +3728,7 @@ unittest
{ {
@disable this(); @disable this();
this(int[] arr) { _arr = arr; } this(int[] arr) { _arr = arr; }
mixin(genInput()); mixin genInput;
@property auto save() { return this; } @property auto save() { return this; }
auto opSlice(size_t i, size_t j) { return typeof(this)(_arr[i .. j]); } auto opSlice(size_t i, size_t j) { return typeof(this)(_arr[i .. j]); }
@property size_t length() { return _arr.length; } @property size_t length() { return _arr.length; }
@ -3733,7 +3737,7 @@ unittest
static struct InitStruct static struct InitStruct
{ {
mixin(genInput()); mixin genInput;
int[] _arr; int[] _arr;
} }
@ -3741,7 +3745,7 @@ unittest
{ {
this(int[] arr) { _arr = arr; } this(int[] arr) { _arr = arr; }
@disable this(); @disable this();
mixin(genInput()); mixin genInput;
auto takeNone() { return typeof(this)(null); } auto takeNone() { return typeof(this)(null); }
int[] _arr; int[] _arr;
} }
@ -3749,14 +3753,14 @@ unittest
static class NormalClass static class NormalClass
{ {
this(int[] arr) {_arr = arr;} this(int[] arr) {_arr = arr;}
mixin(genInput()); mixin genInput;
int[] _arr; int[] _arr;
} }
static class SliceClass static class SliceClass
{ {
this(int[] arr) { _arr = arr; } this(int[] arr) { _arr = arr; }
mixin(genInput()); mixin genInput;
@property auto save() { return new typeof(this)(_arr); } @property auto save() { return new typeof(this)(_arr); }
auto opSlice(size_t i, size_t j) { return new typeof(this)(_arr[i .. j]); } auto opSlice(size_t i, size_t j) { return new typeof(this)(_arr[i .. j]); }
@property size_t length() { return _arr.length; } @property size_t length() { return _arr.length; }
@ -3766,37 +3770,33 @@ unittest
static class TakeNoneClass static class TakeNoneClass
{ {
this(int[] arr) { _arr = arr; } this(int[] arr) { _arr = arr; }
mixin(genInput()); mixin genInput;
auto takeNone() { return new typeof(this)(null); } auto takeNone() { return new typeof(this)(null); }
int[] _arr; int[] _arr;
} }
import std.string : format; import std.string : format;
foreach(range; TypeTuple!(`[1, 2, 3, 4, 5]`, foreach(range; TypeTuple!([1, 2, 3, 4, 5],
`"hello world"`, "hello world",
`"hello world"w`, "hello world"w,
`"hello world"d`, "hello world"d,
`SliceStruct([1, 2, 3])`, SliceStruct([1, 2, 3]),
//@@@BUG@@@ 8339 forces this to be takeExactly //@@@BUG@@@ 8339 forces this to be takeExactly
//`InitStruct([1, 2, 3])`, //`InitStruct([1, 2, 3]),
`TakeNoneStruct([1, 2, 3])`)) TakeNoneStruct([1, 2, 3])))
{ {
mixin(format("enum a = takeNone(%s).empty;", range)); static assert(takeNone(range).empty, typeof(range).stringof);
assert(a, typeof(range).stringof); assert(takeNone(range).empty);
mixin(format("assert(takeNone(%s).empty);", range)); static assert(is(typeof(range) == typeof(takeNone(range))), typeof(range).stringof);
mixin(format("static assert(is(typeof(%s) == typeof(takeNone(%s))), typeof(%s).stringof);",
range, range, range));
} }
foreach(range; TypeTuple!(`NormalStruct([1, 2, 3])`, foreach(range; TypeTuple!(NormalStruct([1, 2, 3]),
`InitStruct([1, 2, 3])`)) InitStruct([1, 2, 3])))
{ {
mixin(format("enum a = takeNone(%s).empty;", range)); static assert(takeNone(range).empty, typeof(range).stringof);
assert(a, typeof(range).stringof); assert(takeNone(range).empty);
mixin(format("assert(takeNone(%s).empty);", range)); static assert(is(typeof(takeExactly(range, 0)) == typeof(takeNone(range))), typeof(range).stringof);
mixin(format("static assert(is(typeof(takeExactly(%s, 0)) == typeof(takeNone(%s))), typeof(%s).stringof);",
range, range, range));
} }
//Don't work in CTFE. //Don't work in CTFE.