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

2024-02-03 Thread kdevel via Digitalmars-d-learn
On Saturday, 3 February 2024 at 02:20:13 UTC, Paul Backus wrote: 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

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

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

2024-02-01 Thread Chris Katko via Digitalmars-d-learn
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 priority = into!(data[2]); ``` instead of: ```D uint time = to!uint

Re: 'auto' keyword

2023-03-12 Thread Ali Çehreli via Digitalmars-d-learn
On 3/12/23 06:07, DLearner wrote: > 1. As a shorthand to make the type of the variable being declared the > same as the type on the right hand side of an initial assignment. As Adam explained, D already has type inference without a special keyword. However, some places where 'auto' (or

Re: 'auto' keyword

2023-03-12 Thread kdevel via Digitalmars-d-learn
On Sunday, 12 March 2023 at 13:27:05 UTC, Adam D Ruppe wrote: [...] *any* storage class will work for type inference. [...] After heaving read [1] I immediately thought of this: void main () { deprecated i = 3; i = 4; } $ dmd test.d test.d(4): Deprecation: variable

Re: 'auto' keyword

2023-03-12 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 12 March 2023 at 15:31:07 UTC, Salih Dincer wrote: Moreover, `auto ref` or `ref auto` is needed in functions. That's because `ref` isn't part of the argument or return value's type, so it isn't covered by **type** inference. Instead, D has a totally separate feature for "

Re: 'auto' keyword

2023-03-12 Thread Salih Dincer via Digitalmars-d-learn
. The auto keyword is really helpful for shortening it. But in at least 2 cases (one of which is interfaces) it should help the compiler. For example, contrary to expected, it is dynamic array: ```d auto arr = [ 1, 2, 3 ]; ``` Moreover, `auto ref` or `ref auto` is needed in functions. SDB@79

Re: 'auto' keyword

2023-03-12 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 12 March 2023 at 13:07:58 UTC, DLearner wrote: Is it correct that this _single_ keyword is used to indicate _two_ quite different things: No, it only actually does #2 in your thing. The type is optional meaning *any* storage class will work for type inference. `auto

'auto' keyword

2023-03-12 Thread DLearner via Digitalmars-d-learn
Is it correct that this _single_ keyword is used to indicate _two_ quite different things: 1. As a shorthand to make the type of the variable being declared the same as the type on the right hand side of an initial assignment. Example: ```auto A = 5;``` makes A an int. 2. To indicate

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-26 Thread Kagamin via Digitalmars-d-learn
Looks like explicitly initialized variable in this case allocates array literal. Uninitialized variable is initialized with init pattern. This may be correct as uninitialized variable isn't guaranteed to hold a value most useful for you, it's only guaranteed to hold a defined value.

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-26 Thread Andrey Zherikov via Digitalmars-d-learn
On Wednesday, 26 October 2022 at 04:40:17 UTC, Salih Dincer wrote: On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov wrote: Does the second piece of code shows a bug or my expectation is not correct (and why if so)? As a result, if this is a bug, Andrey has the right to report it.

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 26 October 2022 at 02:34:24 UTC, Ali Çehreli wrote: On 10/25/22 19:25, Salih Dincer wrote: > with static in main(): If 'static' makes a difference on your side as well, it is your turn to create a bug report. :) (Last time you discovered a bug, I was too quick to report it. :/)

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 19:25, Salih Dincer wrote: > with static in main(): If 'static' makes a difference on your side as well, it is your turn to create a bug report. :) (Last time you discovered a bug, I was too quick to report it. :/) Ali

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Salih Dincer via Digitalmars-d-learn
too, to use a static struct. I also tried the following example because it can work with static in main(): import std; void main() { //static struct X { static struct Y { //... }} static struct Bar { string s; string toString() { return s; } } auto l

Re: auto scope question?

2022-10-25 Thread WhatMeWorry via Digitalmars-d-learn
typeof(screen.output.findSplit("")) s; Perfect. That was the "essence" of my question. But thanks to Ali, I don't have to use such esoteric syntax. D is a wonderful language, but I seem to shoot myself in the foot :)

Re: auto scope question?

2022-10-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/25/22 6:07 PM, WhatMeWorry wrote: I'm naturally getting a undefined identifier `s` error in the return. Is there some way to refactor my code?  I tried to declare s outside of the else brackets like: auto screen = executeShell(cmdLine); auto s; ... {     s = screen.output.findSplit

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 17:16, Salih Dincer wrote: > Excuse me, but they still write in purple prose about dynamic > array literature here! I've heard positive things about D's arrays from people who use D in production. Especially slices... > I've known D for more than 10 years, but the topic we're

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 26, 2022 at 12:16:55AM +, Salih Dincer via Digitalmars-d-learn wrote: [...] > I've known D for more than 10 years, but the topic we're talking about > still seems strange to me. The explanations given are not enough for > me, I'm sorry. > > Can anyone tell me what happens when I

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 25 October 2022 at 20:36:28 UTC, matheus wrote: On int[] a = [1]; int[] b = a.dup; assert([0] !is [0]); // different memory ``` This is interesting, I understand the point of "reference vs copy", and I'm OK with this design choice of, but I wonder in the case of newcomers if

Re: auto scope question?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 15:07, WhatMeWorry wrote: > auto screen = executeShell(cmdLine); > auto s; That can't work because there is no information to infer the type of 's'. Judging from the return type of getPath, perhaps it's string[]: string[] s; This is the question we should answer first

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 13:36, matheus wrote: > On Tuesday, 25 October 2022 at 20:12:25 UTC, Paul Backus wrote: >> Static arrays are value types. What that means is, when we say float[3], there are just 3 floats without any overhead. >> Dynamic arrays are reference types. That phrase can be confusing

auto scope question?

2022-10-25 Thread WhatMeWorry via Digitalmars-d-learn
I'm naturally getting a undefined identifier `s` error in the return. Is there some way to refactor my code? I tried to declare s outside of the else brackets like: auto screen = executeShell(cmdLine); auto s; ... { s = screen.output.findSplit("REG_SZ"); } but that doesn

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 25 October 2022 at 20:27:18 UTC, Ali Çehreli wrote: On 10/25/22 13:12, Paul Backus wrote: > In order to create a copy of a static array Although .dup works for static arrays as well, you meant "dynamic array" and everyones knows it. :) Yes; thank you for the correction. :)

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread matheus via Digitalmars-d-learn
On Tuesday, 25 October 2022 at 20:12:25 UTC, Paul Backus wrote: On Tuesday, 25 October 2022 at 17:54:16 UTC, Salih Dincer wrote: On Tuesday, 25 October 2022 at 17:18:35 UTC, Paul Backus wrote: It's not a bug. They're pointing to the exact same instance of `A` in memory: I don't understand?

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 13:12, Paul Backus wrote: > In order to create a copy of a static array Although .dup works for static arrays as well, you meant "dynamic array" and everyones knows it. :) > with its own block of > memory, separate from the original, you have to use the built-in `.dup` > method:

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 25 October 2022 at 17:54:16 UTC, Salih Dincer wrote: On Tuesday, 25 October 2022 at 17:18:35 UTC, Paul Backus wrote: It's not a bug. They're pointing to the exact same instance of `A` in memory: I don't understand? So I don't understand why it causes problems with dynamic

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 11:23, Steven Schveighoffer wrote: >> Why do I say incorrect things like that? :) > You were right actually. As always! Now I'm confused. :o) Ali

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/25/22 2:03 PM, Ali Çehreli wrote: On 10/25/22 11:01, Ali Çehreli wrote: > static arrays don't have .ptr to point > to any member. Why do I say incorrect things like that? :) Of course static arrays have .ptr as well but that always point to their own body of N elements. They own

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 11:01, Ali Çehreli wrote: > static arrays don't have .ptr to point > to any member. Why do I say incorrect things like that? :) Of course static arrays have .ptr as well but that always point to their own body of N elements. They own their elements... I move away from the keyboard

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 10:54, Salih Dincer wrote: > So I don't understand why it causes problems with > dynamic arrays! So why is there nothing wrong with the static array in > the example below? The same rules as other uses of dynamic arrays... > //A[] a = [A.init];/* In that case, there is a

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 25 October 2022 at 17:18:35 UTC, Paul Backus wrote: It's not a bug. They're pointing to the exact same instance of `A` in memory: I don't understand? So I don't understand why it causes problems with dynamic arrays! So why is there nothing wrong with the static array in the

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
struct A { int[] i; } struct B { A[] a = [A.init]; static B opCall() { return B.init; } } void main() { auto b1 = B.init; b1.writeln; B b2 = B(); b2.writeln; B b3; b3.writeln; } > This fails in run time Not anymore with the above code. Ali

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 25 October 2022 at 16:52:48 UTC, Salih Dincer wrote: On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov wrote: Does the second piece of code shows a bug or my expectation is not correct (and why if so)? This is a bug: ```d void main() { struct B { struct A {

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov wrote: Does the second piece of code shows a bug or my expectation is not correct (and why if so)? This is a bug: ```d void main() { struct B { struct A { int i = 10; } A[] a = [A.init]; } B[2] b;

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Andrey Zherikov via Digitalmars-d-learn
On Tuesday, 25 October 2022 at 14:53:50 UTC, Adam D Ruppe wrote: On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov wrote: A[] a = [A.init]; This is a problem - this is referring to a static array instance, shared across all copies of B. You almost certainly don't want this.

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Andrey Zherikov via Digitalmars-d-learn
construction even when default ctor is disabled: ```d struct A { int[] i; } struct B { A[] a; @disable this(); this(bool) { A[] a = [A.init]; } } void main() { auto b1 = B.init; b1.a[0].i ~= 1; b1.a ~= A.init; b1.a[0].i ~= 11; b1.a[1].i ~= 12

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 07:53, Adam D Ruppe wrote: > On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov wrote: >> A[] a = [A.init]; > > This is a problem - this is referring to a static array instance, shared > across all copies of B. You almost certainly don't want this. Agreed. It should be

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov wrote: A[] a = [A.init]; This is a problem - this is referring to a static array instance, shared across all copies of B. You almost certainly don't want this. That B.a[0] is the *same object* across different

Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Andrey Zherikov via Digitalmars-d-learn
I have the following types (simplified version of my code): ```d struct A { int[] i; } struct B { A[] a = [A.init]; } ``` This code: ```d auto b1 = B.init; b1.a[0].i ~= 1; b1.a ~= A.init; b1.a[0].i ~= 11; b1.a[1].i ~= 12; b1.writeln; auto b2 = B(); b2

Re: auto ref function parameter causes that non copyable struct is copied?

2021-11-10 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Tuesday, 9 November 2021 at 19:30:20 UTC, tchaloupka wrote: On Monday, 8 November 2021 at 23:26:39 UTC, tchaloupka wrote: Bug or feature? :) I've reported it in https://issues.dlang.org/show_bug.cgi?id=22498. It doesn't copy. It just destructs the same object twice... Ouch. Change the

Re: auto ref function parameter causes that non copyable struct is copied?

2021-11-09 Thread tchaloupka via Digitalmars-d-learn
On Monday, 8 November 2021 at 23:26:39 UTC, tchaloupka wrote: Bug or feature? :) I've reported it in https://issues.dlang.org/show_bug.cgi?id=22498.

Re: auto ref function parameter causes that non copyable struct is copied?

2021-11-08 Thread tchaloupka via Digitalmars-d-learn
{ int x; @disable this(this); } unittest { import core.lifetime : move; auto a = A(5); auto b = B(5); a.move; b.move; assert(a == A(5)); assert(b == B(0)); } ``` Yes it should qualify so it should be cleaned out when moved. When I change: ```D auto ref unwrap(EX)(auto

Re: auto ref function parameter causes that non copyable struct is copied?

2021-11-08 Thread jfondren via Digitalmars-d-learn
core.lifetime : move; auto a = A(5); auto b = B(5); a.move; b.move; assert(a == A(5)); assert(b == B(0)); } ```

Re: auto ref function parameter causes that non copyable struct is copied?

2021-11-08 Thread jfondren via Digitalmars-d-learn
On Tuesday, 9 November 2021 at 02:19:28 UTC, Stanislav Blinov wrote: On Monday, 8 November 2021 at 23:26:39 UTC, tchaloupka wrote: ``` auto gen() { Foo f; // <--- this one f.n = 42; return value(f.move()); } void main() { Foo f; f = gen().unwrap.m

Re: auto ref function parameter causes that non copyable struct is copied?

2021-11-08 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 8 November 2021 at 23:26:39 UTC, tchaloupka wrote: ``` auto gen() { Foo f; // <--- this one f.n = 42; return value(f.move()); } void main() { Foo f; f = gen().unwrap.move; } ``` ~this(0) ~this(0) ~this(0) ~this(42) <- this is

auto ref function parameter causes that non copyable struct is copied?

2021-11-08 Thread tchaloupka via Digitalmars-d-learn
Lets have this code: ```D import core.lifetime : forward; import core.stdc.stdio; import std.algorithm : move; struct Value(T) { private T storage; this()(auto ref T val) { storage = forward!val; } ref inout(T) get() inout { return storage; } } Value!T

Re: Return values from auto function

2020-11-07 Thread Piotr Mitana via Digitalmars-d-learn
; this(Success value) { result = value; } this(Failure value) { result = value; } } auto success(T)(T value) { return Result!T(Result!T.Success(value)); } auto failure(string error) { return Result!void(Result!void.Failure(error)); } auto f(int i) { return

Re: Return values from auto function

2020-11-07 Thread Jesse Phillips via Digitalmars-d-learn
t = Algebraic!(int, string) ; void main() {    auto x = true? Result("fish") : Result(6); }

Re: Return values from auto function

2020-11-07 Thread Patrick Schluter via Digitalmars-d-learn
On Saturday, 7 November 2020 at 15:49:13 UTC, James Blachly wrote: ``` retval = i > 0 ? Success!int(i) : Failure("Sorry"); ``` casting each to `Result` compiles, but is verbose: ``` return i > 0 ? cast(Result) Success!int(i) : cast(Result) Failure("Sorry"); ``` ** Could someone more

Re: Return values from auto function

2020-11-07 Thread James Blachly via Digitalmars-d-learn
On 11/6/20 5:51 AM, Andrey Zherikov wrote: I have auto function 'f' that might return either an error (with some text) or a result (with some value). The problem is that the type of the error is not the same as the type of result so compilation fails. ... How can I make the original code

Re: Return values from auto function

2020-11-07 Thread Andrey Zherikov via Digitalmars-d-learn
On Saturday, 7 November 2020 at 01:50:15 UTC, Jesse Phillips wrote: On Friday, 6 November 2020 at 15:06:18 UTC, Andrey Zherikov wrote: On Friday, 6 November 2020 at 14:58:40 UTC, Jesse Phillips wrote: On Friday, 6 November 2020 at 14:20:40 UTC, Andrey Zherikov wrote: This issue seems hit the

Re: Return values from auto function

2020-11-06 Thread Jesse Phillips via Digitalmars-d-learn
On Friday, 6 November 2020 at 15:06:18 UTC, Andrey Zherikov wrote: On Friday, 6 November 2020 at 14:58:40 UTC, Jesse Phillips wrote: On Friday, 6 November 2020 at 14:20:40 UTC, Andrey Zherikov wrote: This issue seems hit the inability to implicitly convert custom types. May be it makes more

Re: Return values from auto function

2020-11-06 Thread Jesse Phillips via Digitalmars-d-learn
On Friday, 6 November 2020 at 20:05:36 UTC, Ferhat Kurtulmuş wrote: On Friday, 6 November 2020 at 10:51:20 UTC, Andrey Zherikov wrote: I have auto function 'f' that might return either an error (with some text) or a result (with some value). The problem is that the type of the error

Re: Return values from auto function

2020-11-06 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 6 November 2020 at 10:51:20 UTC, Andrey Zherikov wrote: I have auto function 'f' that might return either an error (with some text) or a result (with some value). The problem is that the type of the error is not the same as the type of result so compilation fails. [...] Sounds

Re: Return values from auto function

2020-11-06 Thread Mike Parker via Digitalmars-d-learn
On Friday, 6 November 2020 at 15:06:18 UTC, Andrey Zherikov wrote: To clarify my statement: Yes, Result!void and Result!int are different types but I couldn't find a way to implicitly convert one to another. You can't. Structs do not implicitly convert to each other, templated or otherwise.

Re: Return values from auto function

2020-11-06 Thread Andrey Zherikov via Digitalmars-d-learn
On Friday, 6 November 2020 at 14:58:40 UTC, Jesse Phillips wrote: On Friday, 6 November 2020 at 14:20:40 UTC, Andrey Zherikov wrote: This issue seems hit the inability to implicitly convert custom types. May be it makes more sense to ask in a separate thread. The return type must be the same

Re: Return values from auto function

2020-11-06 Thread Jesse Phillips via Digitalmars-d-learn
On Friday, 6 November 2020 at 14:20:40 UTC, Andrey Zherikov wrote: On Friday, 6 November 2020 at 12:03:01 UTC, Paul Backus wrote: You can't. Both return values have to have the same type, which means the failure function has to be able to return more than one type, which means it has to be a

Re: Return values from auto function

2020-11-06 Thread Andrey Zherikov via Digitalmars-d-learn
On Friday, 6 November 2020 at 12:03:01 UTC, Paul Backus wrote: You can't. Both return values have to have the same type, which means the failure function has to be able to return more than one type, which means it has to be a template. This issue seems hit the inability to implicitly convert

Re: Return values from auto function

2020-11-06 Thread Andrey Zherikov via Digitalmars-d-learn
On Friday, 6 November 2020 at 13:59:58 UTC, gbram wrote: On Friday, 6 November 2020 at 12:03:01 UTC, Paul Backus wrote: On Friday, 6 November 2020 at 10:51:20 UTC, Andrey Zherikov wrote: How can I make the original code compilable without templatizing `failure` function? You can't. Both

Re: Return values from auto function

2020-11-06 Thread gbram via Digitalmars-d-learn
On Friday, 6 November 2020 at 12:03:01 UTC, Paul Backus wrote: On Friday, 6 November 2020 at 10:51:20 UTC, Andrey Zherikov wrote: How can I make the original code compilable without templatizing `failure` function? You can't. Both return values have to have the same type, which means the

Re: Return values from auto function

2020-11-06 Thread Paul Backus via Digitalmars-d-learn
On Friday, 6 November 2020 at 10:51:20 UTC, Andrey Zherikov wrote: I can make it work if I add a type to `failure` function but this remove brevity in usage: - auto failure(T)(string error) { return Result!T(Result!T.Failure(error)); } auto f(int i) { return i >

Return values from auto function

2020-11-06 Thread Andrey Zherikov via Digitalmars-d-learn
I have auto function 'f' that might return either an error (with some text) or a result (with some value). The problem is that the type of the error is not the same as the type of result so compilation fails. Here is my code: -- struct Result(T) { struct Success

Re: How auto convert Variant to required function arguments?

2020-10-09 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 9 October 2020 at 16:10:03 UTC, Ferhat Kurtulmuş wrote: On Friday, 9 October 2020 at 15:49:31 UTC, Ferhat Kurtulmuş wrote: On Friday, 9 October 2020 at 00:19:20 UTC, Marcone wrote: How auto convert Variant to required function arguments? import std.variant; import std.stdio

Re: How auto convert Variant to required function arguments?

2020-10-09 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 9 October 2020 at 15:49:31 UTC, Ferhat Kurtulmuş wrote: On Friday, 9 October 2020 at 00:19:20 UTC, Marcone wrote: How auto convert Variant to required function arguments? import std.variant; import std.stdio; Variant a; int mul2(Variant b){    int c = *b.peek!(int);    return

Re: How auto convert Variant to required function arguments?

2020-10-09 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 9 October 2020 at 00:19:20 UTC, Marcone wrote: How auto convert Variant to required function arguments? import std.variant; import std.stdio; Variant a; int mul2(Variant b){    int c = *b.peek!(int);    return 2*c; } int mul3(int b){ return 3*b; } void main() {    a = 5

How auto convert Variant to required function arguments?

2020-10-08 Thread Marcone via Digitalmars-d-learn
How auto convert Variant to required function arguments?

Re: Annotating SortedRange.empty const: Best way to auto-deduce annotations?

2020-09-02 Thread SimonN via Digitalmars-d-learn
On Wednesday, 2 September 2020 at 21:40:59 UTC, Steven Schveighoffer wrote: What they can do is template the `this` parameter. Then if the underlying range supports calling that way, it will work, otherwise it won't. using `template this` should be compatible with the existing code I would

Re: Annotating SortedRange.empty const: Best way to auto-deduce annotations?

2020-09-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/2/20 5:23 PM, SimonN wrote: Hi, About this issue in Phobos: https://issues.dlang.org/show_bug.cgi?id=21216 SortedRange.empty should be const, .front should be inout Just adding const/inout to SortedRange's methods won't be enough; if we add const/inout here, then many other Phobos ranges

Annotating SortedRange.empty const: Best way to auto-deduce annotations?

2020-09-02 Thread SimonN via Digitalmars-d-learn
Hi, About this issue in Phobos: https://issues.dlang.org/show_bug.cgi?id=21216 SortedRange.empty should be const, .front should be inout Just adding const/inout to SortedRange's methods won't be enough; if we add const/inout here, then many other Phobos ranges need to become

Re: safety and auto vectorization

2020-08-04 Thread Andy Balba via Digitalmars-d-learn
Debian 8.3.0-6, dst[]= generates a range error auto a = [1, 2, 3]; auto b = [4, 5, 6]; int[] dst = new int[4]; // note the extra element dst[] = a[] + b[]; writeln(dst[3]);

Re: safety and auto vectorization

2020-08-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/3/20 3:22 PM, Bruce Carneal wrote: Thanks Steve (and Chad).  Summary: underspecified, varying behavior across versions, buggy. Steve, what's the best way for me to report this?  Are spec issues lumped in with the other bugzilla reports? Yep. You can file under dlang.org with the spec

Re: safety and auto vectorization

2020-08-03 Thread Bruce Carneal via Digitalmars-d-learn
On Monday, 3 August 2020 at 18:55:36 UTC, Steven Schveighoffer wrote: On 8/2/20 1:31 PM, Bruce Carneal wrote: import std; void f0(int[] a, int[] b, int[] dst) @safe {     dst[] = a[] + b[]; } [snip of auto-vectorization example] I was surprised that f0 ran just fine with a.length

Re: safety and auto vectorization

2020-08-03 Thread Steven Schveighoffer via Digitalmars-d-learn
(dst.length == minLen); } I was surprised that f0 ran just fine with a.length and b.length geq dst.length.  Is that a bug or a feature? Assuming it's a feature, are f0 and f1 morally equivalent?  I ask because f1 auto-vectorizes in ldc while f0 does not.  Not sure why.  As a guess I'd say

Re: safety and auto vectorization

2020-08-03 Thread Chad Joan via Digitalmars-d-learn
..minLen]; assert(dst.length == minLen); } I was surprised that f0 ran just fine with a.length and b.length geq dst.length. Is that a bug or a feature? Assuming it's a feature, are f0 and f1 morally equivalent? I ask because f1 auto-vectorizes in ldc while f0 does not. Not sure why

safety and auto vectorization

2020-08-02 Thread Bruce Carneal via Digitalmars-d-learn
that f0 ran just fine with a.length and b.length geq dst.length. Is that a bug or a feature? Assuming it's a feature, are f0 and f1 morally equivalent? I ask because f1 auto-vectorizes in ldc while f0 does not. Not sure why. As a guess I'd say that the front end doesn't hoist bounds checks in f0

Re: Finding out ref-ness of the return of an auto ref function

2020-06-13 Thread Stanislav Blinov via Digitalmars-d-learn
by actually forwarding arguments to it (because a function template may have auto ref parameters). Steven's issue report doesn't account for templates, nor overloading, and correctly testing the latter would pretty much require you to match argument types and ref-ness by hand anyway (yuck).

Re: Finding out ref-ness of the return of an auto ref function

2020-06-13 Thread Arafel via Digitalmars-d-learn
On 12/6/20 20:34, Stanislav Blinov wrote: On Friday, 12 June 2020 at 17:50:43 UTC, Arafel wrote: All in all, I still think something like `__traits(isRef,return)` would still be worth adding! After all the compiler already has all the information, so it's just about exposing it. I'm trying to

Re: Finding out ref-ness of the return of an auto ref function

2020-06-12 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 12 June 2020 at 17:50:43 UTC, Arafel wrote: All in all, I still think something like `__traits(isRef,return)` would still be worth adding! After all the compiler already has all the information, so it's just about exposing it. I'm trying to think of a library solution, but I find

Re: Finding out ref-ness of the return of an auto ref function

2020-06-12 Thread Arafel via Digitalmars-d-learn
On 12/6/20 18:15, Paul Backus wrote: I think I have something that works: ref int foo(); int bar(); enum isLvalue(string expr) = q{     __traits(compiles, (auto ref x) {     static assert(__traits(isRef, x));     }(} ~ expr ~ q{)) }; pragma(msg, mixin(isLvalue!"foo()")

Re: Finding out ref-ness of the return of an auto ref function

2020-06-12 Thread Paul Backus via Digitalmars-d-learn
On Friday, 12 June 2020 at 14:56:41 UTC, Arafel wrote: Hi all, I'm hitting a problem that it's making crazy... is there any way to find out if the return of an `auto ref` function is actually ref or not? So, according to the documentation [1] it depends on the return expressions... however

Finding out ref-ness of the return of an auto ref function

2020-06-12 Thread Arafel via Digitalmars-d-learn
Hi all, I'm hitting a problem that it's making crazy... is there any way to find out if the return of an `auto ref` function is actually ref or not? So, according to the documentation [1] it depends on the return expressions... however in my case I'm implementing `opDispatch` in a wrapper

Re: I want Sublime 3 D auto import !

2020-06-04 Thread Виталий Фадеев via Digitalmars-d-learn
On Thursday, 4 June 2020 at 04:48:22 UTC, bauss wrote: On Wednesday, 3 June 2020 at 11:54:57 UTC, Виталий Фадеев wrote: On Tuesday, 2 June 2020 at 20:08:09 UTC, bauss wrote: What happens if you have the same symbol in multiple modules? Ex. two libraries that implement symbols with same name.

Re: I want Sublime 3 D auto import !

2020-06-03 Thread bauss via Digitalmars-d-learn
On Wednesday, 3 June 2020 at 11:54:57 UTC, Виталий Фадеев wrote: On Tuesday, 2 June 2020 at 20:08:09 UTC, bauss wrote: What happens if you have the same symbol in multiple modules? Ex. two libraries that implement symbols with same name. First module will inserted. Is there a way to be

Re: I want Sublime 3 D auto import !

2020-06-03 Thread Виталий Фадеев via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 20:08:09 UTC, bauss wrote: What happens if you have the same symbol in multiple modules? Ex. two libraries that implement symbols with same name. First module will inserted. Is there a way to be selective? I want it too! :) And what about keyboard shortcut?

Re: I want Sublime 3 D auto import !

2020-06-03 Thread aberba via Digitalmars-d-learn
On Monday, 1 June 2020 at 17:28:16 UTC, Johannes Loher wrote: On Monday, 1 June 2020 at 16:18:44 UTC, Виталий Фадеев wrote: [...] Demanding stuff usually doesn't work in this community. The usual answer is something like this: If you care about this, implement it yourself or pay somebody to

Re: I want Sublime 3 D auto import !

2020-06-02 Thread bauss via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 06:00:10 UTC, Виталий Фадеев wrote: On Monday, 1 June 2020 at 18:55:03 UTC, Paul Backus wrote: On Monday, 1 June 2020 at 16:18:44 UTC, Виталий Фадеев wrote: I do it! https://github.com/vitalfadeev/SublimeDlangAutoImport What happens if you have the same symbol in

Re: I want Sublime 3 D auto import !

2020-06-02 Thread welkam via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 06:00:10 UTC, Виталий Фадеев wrote: On Monday, 1 June 2020 at 18:55:03 UTC, Paul Backus wrote: On Monday, 1 June 2020 at 16:18:44 UTC, Виталий Фадеев wrote: I do it! https://github.com/vitalfadeev/SublimeDlangAutoImport Cool. I dont use classe but I see how this

Re: I want Sublime 3 D auto import !

2020-06-02 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 06:00:10 UTC, Виталий Фадеев wrote: On Monday, 1 June 2020 at 18:55:03 UTC, Paul Backus wrote: On Monday, 1 June 2020 at 16:18:44 UTC, Виталий Фадеев wrote: I do it! https://github.com/vitalfadeev/SublimeDlangAutoImport Great! You should make a post about it in

Re: I want Sublime 3 D auto import !

2020-06-02 Thread Виталий Фадеев via Digitalmars-d-learn
On Monday, 1 June 2020 at 18:55:03 UTC, Paul Backus wrote: On Monday, 1 June 2020 at 16:18:44 UTC, Виталий Фадеев wrote: I do it! https://github.com/vitalfadeev/SublimeDlangAutoImport

Re: I want Sublime 3 D auto import !

2020-06-01 Thread Paul Backus via Digitalmars-d-learn
On Monday, 1 June 2020 at 16:18:44 UTC, Виталий Фадеев wrote: I want Sublime D auto import ! When typing code like this: class Uno : IStylable { // } I want will be auto added "import IStylable" at begin of file. Like this: import ui.istylable :

Re: I want Sublime 3 D auto import !

2020-06-01 Thread Johannes Loher via Digitalmars-d-learn
On Monday, 1 June 2020 at 16:18:44 UTC, Виталий Фадеев wrote: I want Sublime D auto import ! When typing code like this: class Uno : IStylable { // } I want will be auto added "import IStylable" at begin of file. Like this: import ui.istylable :

I want Sublime 3 D auto import !

2020-06-01 Thread Виталий Фадеев via Digitalmars-d-learn
I want Sublime D auto import ! When typing code like this: class Uno : IStylable { // } I want will be auto added "import IStylable" at begin of file. Like this: import ui.istylable : IStylable; class Uno : IStylable { // }

Re: Is there a way to tell if an auto ref parameter is by ref or by value?

2020-05-10 Thread NaN via Digitalmars-d-learn
On Sunday, 10 May 2020 at 01:15:58 UTC, Anonymouse wrote: On Sunday, 10 May 2020 at 00:33:07 UTC, NaN wrote: Ie something like.. auto Foo(T)(auto ref T x) { static if (isByRef(x)) { } else { } } __traits(isRef, x) Thanks :)

Re: Is there a way to tell if an auto ref parameter is by ref or by value?

2020-05-09 Thread Anonymouse via Digitalmars-d-learn
On Sunday, 10 May 2020 at 00:33:07 UTC, NaN wrote: Ie something like.. auto Foo(T)(auto ref T x) { static if (isByRef(x)) { } else { } } __traits(isRef, x)

Is there a way to tell if an auto ref parameter is by ref or by value?

2020-05-09 Thread NaN via Digitalmars-d-learn
Ie something like.. auto Foo(T)(auto ref T x) { static if (isByRef(x)) { } else { } }

Re: How make DMD auto link imported modules?

2020-04-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 21 April 2020 at 21:36:57 UTC, Marcone wrote: When I create a module, for exemple mymodule.d and import im my main program using "import mymodule" I need add mymodule.d in DMD command line manually. How can make it automatic? dmd -i

How make DMD auto link imported modules?

2020-04-21 Thread Marcone via Digitalmars-d-learn
When I create a module, for exemple mymodule.d and import im my main program using "import mymodule" I need add mymodule.d in DMD command line manually. How can make it automatic?

Re: auto vectorization notes

2020-03-28 Thread Bruce Carneal via Digitalmars-d-learn
find it readable. There are many waypoints on the readability <==> performance axis. If ispc works for you along that axis, great! I find SIMT code readability better than SIMD but a little worse than auto-vectorizable kernels. Hugely better performance though for less effort tha

  1   2   3   4   5   6   7   >