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: Why does indexing a string inside of a recursive call yield a different result?

2020-05-10 Thread bauss via Digitalmars-d-learn
On Sunday, 10 May 2020 at 10:02:18 UTC, Adnan wrote: In my naive implementation of edit-distance finder, I have to check whether the last characters of two strings match: ulong editDistance(const string a, const string b) { if (a.length == 0) return b.length; if (b.length ==

Re: Why does indexing a string inside of a recursive call yield a different result?

2020-05-10 Thread ag0aep6g via Digitalmars-d-learn
On 10.05.20 12:02, Adnan wrote: ulong editDistance(const string a, const string b) {     if (a.length == 0)     return b.length;     if (b.length == 0)     return a.length;     const auto delt = a[$ - 1] == b[$ - 1] ? 0 : 1;     import std.algorithm : min;     return min(  

Why does indexing a string inside of a recursive call yield a different result?

2020-05-10 Thread Adnan via Digitalmars-d-learn
In my naive implementation of edit-distance finder, I have to check whether the last characters of two strings match: ulong editDistance(const string a, const string b) { if (a.length == 0) return b.length; if (b.length == 0) return a.length; const auto delt =

Function Templates with Only Template Parameters and UFCS

2020-05-10 Thread Seven Seas via Digitalmars-d-learn
Given the code: ``` auto foo(alias A, string str)() { // do stuff } struct Bar { // members } Bar bar; bar.foo!"hello"; // This is an error. Would have to do foo!(bar, "hello") ``` Assuming that I haven't misunderstood or borked something, having UFCS for function templates whose

Re: How to get the UDAs for a function parameter correctly?

2020-05-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 11 May 2020 at 02:25:39 UTC, Heromyth wrote: I want to get the UDAs for for a function parameter. Here the test code and I got some errors: I think my blog aside is one of the few if only write-ups on how to do this:

Re: How to get the UDAs for a function parameter correctly?

2020-05-10 Thread Heromyth via Digitalmars-d-learn
On Monday, 11 May 2020 at 02:34:32 UTC, Adam D. Ruppe wrote: On Monday, 11 May 2020 at 02:25:39 UTC, Heromyth wrote: I want to get the UDAs for for a function parameter. Here the test code and I got some errors: I think my blog aside is one of the few if only write-ups on how to do this:

How to get the UDAs for a function parameter correctly?

2020-05-10 Thread Heromyth via Digitalmars-d-learn
I want to get the UDAs for for a function parameter. Here the test code and I got some errors: source/app.d(29,33): Error: first argument is not a symbol source/app.d(39,15): Error: template instance app.test!(ClassA) error instantiating How can I fix this? Would this be a bug? Thanks.