mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 21:51:40 +03:00
Rename SumType.get to getByIndex
This commit is contained in:
parent
40daf61851
commit
fe64ac592b
1 changed files with 15 additions and 15 deletions
|
@ -323,7 +323,7 @@ private:
|
||||||
@trusted
|
@trusted
|
||||||
// Explicit return type omitted
|
// Explicit return type omitted
|
||||||
// Workaround for https://github.com/dlang/dmd/issues/20549
|
// Workaround for https://github.com/dlang/dmd/issues/20549
|
||||||
ref get(size_t tid)() inout
|
ref getByIndex(size_t tid)() inout
|
||||||
if (tid < Types.length)
|
if (tid < Types.length)
|
||||||
{
|
{
|
||||||
assert(tag == tid,
|
assert(tag == tid,
|
||||||
|
@ -1154,7 +1154,7 @@ version (D_BetterC) {} else
|
||||||
alias MySum = SumType!(ubyte, void*[2]);
|
alias MySum = SumType!(ubyte, void*[2]);
|
||||||
|
|
||||||
MySum x = [null, cast(void*) 0x12345678];
|
MySum x = [null, cast(void*) 0x12345678];
|
||||||
void** p = &x.get!1[1];
|
void** p = &x.getByIndex!1[1];
|
||||||
x = ubyte(123);
|
x = ubyte(123);
|
||||||
|
|
||||||
assert(*p != cast(void*) 0x12345678);
|
assert(*p != cast(void*) 0x12345678);
|
||||||
|
@ -1186,8 +1186,8 @@ version (D_BetterC) {} else
|
||||||
catch (Exception e) {}
|
catch (Exception e) {}
|
||||||
|
|
||||||
assert(
|
assert(
|
||||||
(x.tag == 0 && x.get!0.value == 123) ||
|
(x.tag == 0 && x.getByIndex!0.value == 123) ||
|
||||||
(x.tag == 1 && x.get!1.value == 456)
|
(x.tag == 1 && x.getByIndex!1.value == 456)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1246,8 +1246,8 @@ version (D_BetterC) {} else
|
||||||
SumType!(S[1]) x = [S(0)];
|
SumType!(S[1]) x = [S(0)];
|
||||||
SumType!(S[1]) y = x;
|
SumType!(S[1]) y = x;
|
||||||
|
|
||||||
auto xval = x.get!0[0].n;
|
auto xval = x.getByIndex!0[0].n;
|
||||||
auto yval = y.get!0[0].n;
|
auto yval = y.getByIndex!0[0].n;
|
||||||
|
|
||||||
assert(xval != yval);
|
assert(xval != yval);
|
||||||
}
|
}
|
||||||
|
@ -1332,8 +1332,8 @@ version (D_BetterC) {} else
|
||||||
SumType!S y;
|
SumType!S y;
|
||||||
y = x;
|
y = x;
|
||||||
|
|
||||||
auto xval = x.get!0.n;
|
auto xval = x.getByIndex!0.n;
|
||||||
auto yval = y.get!0.n;
|
auto yval = y.getByIndex!0.n;
|
||||||
|
|
||||||
assert(xval != yval);
|
assert(xval != yval);
|
||||||
}
|
}
|
||||||
|
@ -1407,8 +1407,8 @@ version (D_BetterC) {} else
|
||||||
SumType!S x = S();
|
SumType!S x = S();
|
||||||
SumType!S y = x;
|
SumType!S y = x;
|
||||||
|
|
||||||
auto xval = x.get!0.n;
|
auto xval = x.getByIndex!0.n;
|
||||||
auto yval = y.get!0.n;
|
auto yval = y.getByIndex!0.n;
|
||||||
|
|
||||||
assert(xval != yval);
|
assert(xval != yval);
|
||||||
}
|
}
|
||||||
|
@ -1902,10 +1902,10 @@ private template matchImpl(Flag!"exhaustive" exhaustive, handlers...)
|
||||||
* argument's tag, so there's no need for TagTuple.
|
* argument's tag, so there's no need for TagTuple.
|
||||||
*/
|
*/
|
||||||
enum handlerArgs(size_t caseId) =
|
enum handlerArgs(size_t caseId) =
|
||||||
"args[0].get!(" ~ toCtString!caseId ~ ")()";
|
"args[0].getByIndex!(" ~ toCtString!caseId ~ ")()";
|
||||||
|
|
||||||
alias valueTypes(size_t caseId) =
|
alias valueTypes(size_t caseId) =
|
||||||
typeof(args[0].get!(caseId)());
|
typeof(args[0].getByIndex!(caseId)());
|
||||||
|
|
||||||
enum numCases = SumTypes[0].Types.length;
|
enum numCases = SumTypes[0].Types.length;
|
||||||
}
|
}
|
||||||
|
@ -1931,7 +1931,7 @@ private template matchImpl(Flag!"exhaustive" exhaustive, handlers...)
|
||||||
|
|
||||||
template getType(size_t i)
|
template getType(size_t i)
|
||||||
{
|
{
|
||||||
alias getType = typeof(args[i].get!(tags[i])());
|
alias getType = typeof(args[i].getByIndex!(tags[i])());
|
||||||
}
|
}
|
||||||
|
|
||||||
alias valueTypes = Map!(getType, Iota!(tags.length));
|
alias valueTypes = Map!(getType, Iota!(tags.length));
|
||||||
|
@ -2156,7 +2156,7 @@ private template handlerArgs(size_t caseId, typeCounts...)
|
||||||
{
|
{
|
||||||
handlerArgs = AliasSeq!(
|
handlerArgs = AliasSeq!(
|
||||||
handlerArgs,
|
handlerArgs,
|
||||||
"args[" ~ toCtString!i ~ "].get!(" ~ toCtString!(tags[i]) ~ ")(), "
|
"args[" ~ toCtString!i ~ "].getByIndex!(" ~ toCtString!(tags[i]) ~ ")(), "
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2420,7 +2420,7 @@ version (D_Exceptions)
|
||||||
(ref double d) { d *= 2; }
|
(ref double d) { d *= 2; }
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(value.get!1.isClose(6.28));
|
assert(value.getByIndex!1.isClose(6.28));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unreachable handlers
|
// Unreachable handlers
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue