Compare commits

...

2 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire f84f9caa1f SectorType
- More compile-time checks added
2024-05-02 15:57:47 +02:00
Tristan B. Velloza Kildaire ba4dbd975f SectorType
- More compile-time checks added
2024-05-02 15:49:33 +02:00
1 changed files with 53 additions and 3 deletions

View File

@ -654,16 +654,66 @@ private struct Sector(T)
}
// TODO: Make a bit better
import std.traits : hasMember, hasStaticMember, Parameters;
import std.meta : AliasSeq;
import std.traits : hasMember, hasStaticMember, Parameters, arity, ReturnType, TemplateArgsOf;
import std.meta : AliasSeq, staticIndexOf;
private bool isSector(S)()
{
bool s = true;
s = hasMember!(S, "opSlice") && __traits(isSame, Parameters!(S.opSlice), AliasSeq!(size_t, size_t));
// if()
alias args = TemplateArgsOf!(S);
pragma(msg, args);
static if(!args.length)
{
return false;
}
alias T = args[0];
// Has opSlice(size_t, size_t) with T[] return
s &= hasMember!(S, "opSlice") &&
__traits(isSame, Parameters!(S.opSlice), AliasSeq!(size_t, size_t)) &&
__traits(isSame, ReturnType!(S.opSlice), T[]);
// Has opSlice() with T[] return
bool foundNonParamOpSlice = false;
foreach(func; __traits(getOverloads, S, "opSlice"))
{
if(arity!(func) == 0)
{
static if(__traits(isSame, ReturnType!(S.opSlice), T[]))
{
foundNonParamOpSlice = true;
}
}
}
s &= foundNonParamOpSlice;
// s &= hasMember!(S, "opSlice") && arity!(S.) == 0;
pragma(msg, __traits(getFunctionAttributes, S.length));
pragma(msg, 3LU > -1);
// pragma(msg, staticIndexOf!("@property", __traits(getFunctionAttributes, S.length)) == -1);
// Has length method
s &= hasMember!(S, "length") &&
__traits(isSame, ReturnType!(S.length), size_t) &&
staticIndexOf!("@property", __traits(getFunctionAttributes, S.length)) != -1;
// Has opDollar with size_t return
s &= hasMember!(S, "opDollar") &&
__traits(isSame, Parameters!(S.opDollar), AliasSeq!()) &&
__traits(isSame, ReturnType!(S.opDollar), size_t);
// Has opIndex(size_t) with T return
s &= hasMember!(S, "opIndex") &&
__traits(isSame, Parameters!(S.opIndex), AliasSeq!(size_t)) &&
__traits(isSame, ReturnType!(S.opIndex), T);
// Has opIndexAssign(size_t) with T return
s &= hasMember!(S, "opIndexAssign") &&
__traits(isSame, Parameters!(S.opIndexAssign), AliasSeq!(T, size_t)) &&
__traits(isSame, ReturnType!(S.opIndexAssign), void);
return s;
}