On Friday, 2 February 2024 at 08:22:42 UTC, Carl Sturtivant wrote:
It seems I cannot pass e.g. an int argument to a Variant function parameter. What's the simplest way to work around this restriction?

You'd have to implement the function that accepts the parameters and wraps in a Variant.

This is the best I can come up with, which should be copy/pasteable to other shims:

```d
void foo(Variant x, Variant y) { ... }

import std.meta : allSatisfy;

enum isVariant(T) = is(T == Variant);

// this is going to suck at CTFE but...
string argsAsVariants(size_t count)
{
   import std.format;
   import std.range;
   import std.alglorithm;
   import std.array;
return iota(count).map!(i => format("Variant(args[%s])", i).join(",");
}

// shim
auto foo(Args...)(Args args) if (!allSatisfy!(isVariant, Args))
{
    mixin("return foo(", argsAsVariants(args.length), ");");
}
```

-Steve

Reply via email to