What is the proper way to outline static-if-conditions ?
drug
drug2004 at bk.ru
Sun Oct 10 14:08:13 UTC 2021
You just need to check if T is a pointer:
```D
import std;
alias DA = int[];
alias SA = int[3];
alias PSA = SA*;
alias PDA = DA*;
version(all)
enum isPointedStaticArray(T) = isPointer!T &&
isStaticArray!(PointerTarget!T);
else
enum isPointedStaticArray(T) = isPointer!T && is(PointerTarget!T :
P[N], P, size_t N); // this way you can get array length
static assert(!isPointedStaticArray!DA);
static assert(!isPointedStaticArray!SA);
static assert(!isPointedStaticArray!PDA);
static assert( isPointedStaticArray!PSA);
void main()
{
}
```
https://run.dlang.io/is/qKdx1D
Also you can use another way to detect static array - it can be useful
if you need to get its length
More information about the Digitalmars-d-learn
mailing list