On Sunday, 10 October 2021 at 15:15:51 UTC, drug wrote:
It would be nice if one could use pattern-matching for it in
D. Is this possible?
As I know it's impossible, but you can use a regular template:
...
If anyone is interested in pattern matching, someone provides a
package "dpmatch"
On Sunday, 10 October 2021 at 15:15:51 UTC, drug wrote:
As I know it's impossible, but you can use a regular template:
```d
template isPointedStaticArray(T)
{
static if (isPointer!T)
enum isPointedStaticArray =
isStaticArray!(PointerTarget!T);
else
enum
On 10.10.2021 18:01, Elmar wrote:
Well, I just wondered why your code would compile and mine wouldn't. The
`version(all)` variant will not compile on my computer with `rdmd`
because `PointerTarget` only allows pointers.
It depends on compiler version. This variant is compiled on version
On Sunday, 10 October 2021 at 15:01:17 UTC, Elmar wrote:
```d
enum isPointedStaticArray(T) = is(PointerTarget!T : P[N], P,
size_t N);
```
```d
enum isPointedStaticArray(X : P*, P) =
.isStaticArray!(PointerTarget!X);
```
`isStaticArray` is a good example that makes me ask how to
On Sunday, 10 October 2021 at 14:36:50 UTC, Elmar wrote:
On Sunday, 10 October 2021 at 14:08:13 UTC, drug wrote:
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) =
On Sunday, 10 October 2021 at 14:08:13 UTC, drug wrote:
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
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 &&
PS: the title is a misnomer. `is(T : P*, P) && isStaticArray!P`
doesn't either compile when inlined because `P` is not defined
when not matched.