Re: Scripting with Variant from std.variant: parameter passing

2024-02-03 Thread Carl Sturtivant via Digitalmars-d-learn
On Friday, 2 February 2024 at 20:58:12 UTC, Paul Backus wrote: Another variation on the same theme: ```d /// map over a variadic argument list template mapArgs(alias fun) { auto mapArgs(Args...)(auto ref Args args) { import std.typecons: tuple;

Re: Scripting with Variant from std.variant: parameter passing

2024-02-03 Thread Anonymouse via Digitalmars-d-learn
On Saturday, 3 February 2024 at 08:04:40 UTC, Danilo wrote: To be honest, this doesn't make sense. `if (!is(T : Variant))` returns true for inputs like 42, "hello", 3.14f, but the input is not a Variant but a random type. Yes, it's nice that it works in this case. It's just not logical, it

Re: Scripting with Variant from std.variant: parameter passing

2024-02-03 Thread Danilo via Digitalmars-d-learn
On Friday, 2 February 2024 at 11:31:09 UTC, Anonymouse wrote: 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? The easiest thing would be to

Re: Scripting with Variant from std.variant: parameter passing

2024-02-02 Thread Paul Backus via Digitalmars-d-learn
On Friday, 2 February 2024 at 20:28:50 UTC, Carl Sturtivant wrote: On Friday, 2 February 2024 at 19:22:22 UTC, Steven Schveighoffer wrote: ```d // shim auto foo(Args...)(Args args) if (!allSatisfy!(isVariant, Args)) { mixin("return foo(", argsAsVariants(args.length), ");"); } ``` Thanks

Re: Scripting with Variant from std.variant: parameter passing

2024-02-02 Thread Carl Sturtivant via Digitalmars-d-learn
On Friday, 2 February 2024 at 19:22:22 UTC, Steven Schveighoffer wrote: ```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

Re: Scripting with Variant from std.variant: parameter passing

2024-02-02 Thread Steven Schveighoffer via Digitalmars-d-learn
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.

Re: Scripting with Variant from std.variant: parameter passing

2024-02-02 Thread Anonymouse via Digitalmars-d-learn
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? The easiest thing would be to actually pass it a `Variant` with

Re: Scripting with Variant from std.variant: parameter passing

2024-02-02 Thread Danilo via Digitalmars-d-learn
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? Just tell the compiler clearly what you want. ```d import std; void f(Variant x) {

Scripting with Variant from std.variant: parameter passing

2024-02-02 Thread Carl Sturtivant via Digitalmars-d-learn
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?