Re: template/mixin magic for to! auto inferring type from variable

2024-02-02 Thread Paul Backus via Digitalmars-d-learn
On Friday, 2 February 2024 at 23:25:37 UTC, Chris Katko wrote: The auto solution won't work for a struct however which I'm using: ```D struct procTable{ //contains all the fields inside a file I'm parsing uint time; int priority; string name; // etc } ``` Maybe you can use

Re: template/mixin magic for to! auto inferring type from variable

2024-02-02 Thread Chris Katko via Digitalmars-d-learn
On Friday, 2 February 2024 at 21:01:53 UTC, Paul Backus wrote: No, D only does bottom-up type inference, not top down. If you want to avoid repeating the type, use `auto` on the left side: ```d auto time = to!uint(data[1]); auto priority = to!int(data[2]); ``` Okay thanks. It finally

Re: template/mixin magic for to! auto inferring type from variable

2024-02-02 Thread Paul Backus via Digitalmars-d-learn
On Friday, 2 February 2024 at 07:43:09 UTC, Chris Katko wrote: Is there some way to do: ```D string[3] data; //strings from some file input, some are ints, uints, etc. auto into!(T)(T value){return to!???(value); } // ??? uint time = into!(data[1]); // We already know this is uint int

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.

profiling vibe

2024-02-02 Thread Jordan Wilson via Digitalmars-d-learn
I can't seem to be able to use `--profile` with vibe: ```shell dub init -t vibe.d dub build --build=profile ../../.dub/packages/vibe-core/2.7.3/vibe-core/source/vibe/internal/async.d-mixin-119(142,3): Warning: statement is not reachable

Re: sokol-d: Static Struct

2024-02-02 Thread Matheus Catarino via Digitalmars-d-learn
On Saturday, 30 December 2023 at 19:27:08 UTC, Matheus Catarino wrote: Hi everyone.  Currently I'm working on D binding for sokol project (truly a dual bindgen [sokol-tools, sokol-header]) which could be merged into the upstream project. Up to now, my "ideal" configuration has been to

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?