Re: Creating fixed array on stack

2019-01-11 Thread Dgame via Digitalmars-d-learn
On Friday, 11 January 2019 at 14:46:36 UTC, Andrey wrote: Hi, In C++ you can create a fixed array on stack: int count = getCount(); int myarray[count]; In D the "count" is part of type and must be known at CT but in example it is RT. How to do such thing in D? Without using of heap. You co

Re: D'ish similar_text?

2018-05-10 Thread Dgame via Digitalmars-d-learn
On Thursday, 10 May 2018 at 20:38:12 UTC, Vladimir Panteleev wrote: On Thursday, 10 May 2018 at 20:32:11 UTC, Dgame wrote: immutable size_t len = s1.length + s2.length; percent = (len - distance) * 100.0 / len; Note that this formula will give you only 50% similarity for "abc" and "de

Re: D'ish similar_text?

2018-05-10 Thread Dgame via Digitalmars-d-learn
On Thursday, 10 May 2018 at 20:13:49 UTC, Vladimir Panteleev wrote: On Thursday, 10 May 2018 at 20:08:04 UTC, Dgame wrote: void similar_text_similar_str(char* txt1, size_t len1, char* That looks like an implementation of Levenshtein distance. We have one in Phobos: https://dlang.org/library

D'ish similar_text?

2018-05-10 Thread Dgame via Digitalmars-d-learn
I'm in need for some sort of string similarity comparision. I've found soundex but that didn't solved my needs. After some search I found a C implementation of similar_text, but that is quite ugly... I was able to let it work in D but it's still somewhat messy. Is there any D implementation of

Re: Static Array with negative index results in a strange error-message

2018-04-23 Thread Dgame via Digitalmars-d-learn
It's really fun playing around: char[int.max - 1] c; results in Internal error: dmd/backend/cgcod.c 634 with DMD 2.079. Guess I or somebody else should report this.

Re: Static Array with negative index results in a strange error-message

2018-04-23 Thread Dgame via Digitalmars-d-learn
On Monday, 23 April 2018 at 13:48:07 UTC, Steven Schveighoffer wrote: On 4/23/18 9:32 AM, Dgame wrote: char[-1] c; results in Error: char[18446744073709551615LU] size 1 * 18446744073709551615 exceeds 0x7fff size limit for static array Should we fix that? A negative index should be IMO

Static Array with negative index results in a strange error-message

2018-04-23 Thread Dgame via Digitalmars-d-learn
char[-1] c; results in Error: char[18446744073709551615LU] size 1 * 18446744073709551615 exceeds 0x7fff size limit for static array Should we fix that? A negative index should be IMO detected sooner/with a cleaner error message.

Re: Assoc. Array and struct with immutable member

2018-04-17 Thread Dgame via Digitalmars-d-learn
On Tuesday, 17 April 2018 at 11:38:17 UTC, Jonathan M Davis wrote: On Sunday, April 15, 2018 17:59:01 Dgame via Digitalmars-d-learn wrote: How am I supposed to insert a struct with immutable members into an assoc. array? Reduced example: struct A { immutable string name; } A[string

Re: Ldc on Windows

2018-04-17 Thread Dgame via Digitalmars-d-learn
On Tuesday, 17 April 2018 at 11:01:21 UTC, Nicholas Wilson wrote: On Tuesday, 17 April 2018 at 10:17:56 UTC, Dgame wrote: Ah, I found the msvcEnv.bat and I told me that I have to VSC installation. Solved! You should also be able to use -link-internally /LLMV's lld if you don't want to install

Re: Ldc on Windows

2018-04-17 Thread Dgame via Digitalmars-d-learn
On Tuesday, 17 April 2018 at 09:42:01 UTC, Dgame wrote: I'm trying to use Ldc on Windows, but I get these linker errors: OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html OPTLINK : Warning 9: Unknown

Ldc on Windows

2018-04-17 Thread Dgame via Digitalmars-d-learn
I'm trying to use Ldc on Windows, but I get these linker errors: OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html OPTLINK : Warning 9: Unknown Option : OUT OPTLINK : Warning 9: Unknown Option : LIBPA

Assoc. Array and struct with immutable member

2018-04-15 Thread Dgame via Digitalmars-d-learn
How am I supposed to insert a struct with immutable members into an assoc. array? Reduced example: struct A { immutable string name; } A[string] as; as["a"] = A("a"); // Does not work

Re: Rvalue references

2018-01-10 Thread Dgame via Digitalmars-d-learn
On Wednesday, 10 January 2018 at 14:41:21 UTC, Steven Schveighoffer wrote: On 1/10/18 3:08 AM, Dgame wrote: On Wednesday, 10 January 2018 at 01:56:02 UTC, Steven Schveighoffer wrote: But current auto ref is what we have, so I would recommend using it. I would recommend to ignore auto ref for

Re: Rvalue references

2018-01-10 Thread Dgame via Digitalmars-d-learn
On Wednesday, 10 January 2018 at 01:56:02 UTC, Steven Schveighoffer wrote: But current auto ref is what we have, so I would recommend using it. I would recommend to ignore auto ref for rvalue references. It generates 2^N functions where N is the amount of auto ref parameters. That the most aw

Re: How do I pass a type as parameter in this method?

2017-12-19 Thread Dgame via Digitalmars-d-learn
On Tuesday, 19 December 2017 at 15:19:53 UTC, Marc wrote: On Tuesday, 19 December 2017 at 00:01:00 UTC, Ali Çehreli wrote: On 12/18/2017 03:54 PM, Ali Çehreli wrote: On 12/18/2017 02:58 PM, Marc wrote: Here's another experiment: template FirstOf(T...) { template otherwise(D) { st

Re: Sort characters in string

2017-12-06 Thread Dgame via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 09:25:20 UTC, Biotronic wrote: On Wednesday, 6 December 2017 at 08:59:09 UTC, Fredrik Boulund wrote: string word = "longword"; writeln(sort(word)); But that doesn't work because I guess a string is not the type of range required for sort? Yeah, narrow (non-UT

Re: Temporary objects as function parameters or when-is-this-shit-going-to-end?

2017-10-13 Thread Dgame via Digitalmars-d-learn
On Friday, 13 October 2017 at 12:08:00 UTC, Jack Applegame wrote: On Friday, 13 October 2017 at 12:03:55 UTC, Dgame wrote: Interesting. If you remove the CTor in Foo it works again. If you remove DTor it works again too. :) That's one of these times where it would be helpful to see the gener

Re: Temporary objects as function parameters or when-is-this-shit-going-to-end?

2017-10-13 Thread Dgame via Digitalmars-d-learn
On Friday, 13 October 2017 at 10:35:56 UTC, Jack Applegame wrote: If you don't want to get the great PITA, never create temporary objects in function parameters. I recently spent a whole day digging through my reference counted containers library. But nasty bug was not there, but in the compile

Re: No polymorphism?

2017-07-24 Thread Dgame via Digitalmars-d-learn
On Monday, 24 July 2017 at 18:15:20 UTC, Steven Schveighoffer wrote: On 7/24/17 1:29 PM, Dgame wrote: Why isn't the compiler able to deduce S[] => I[]? Or is it just me? I've tried dmd 2.075 I know you got the explanation already, but just in case you actually need to call something like te

Re: No polymorphism?

2017-07-24 Thread Dgame via Digitalmars-d-learn
On Monday, 24 July 2017 at 17:33:48 UTC, Adam D. Ruppe wrote: On Monday, 24 July 2017 at 17:29:55 UTC, Dgame wrote: S[] ss = [new S()]; test1(ss); // Fails Why isn't the compiler able to deduce S[] => I[]? Or is it just me? This is exactly because of polymorphism. Consider th

No polymorphism?

2017-07-24 Thread Dgame via Digitalmars-d-learn
I may be just tired, but could somebody explain this behaviour to me? It seems odd to me: interface I { } class S : I { } void test1(I[]) { } void test2(I) { } void main() { test1([new S()]); // Works test2(new S()); // Works I i = new S(); test2

Re: Static array with parameter based size?

2017-07-11 Thread Dgame via Digitalmars-d-learn
On Tuesday, 11 July 2017 at 08:23:02 UTC, Miguel L wrote: I need to create a non-dynamic array like this void f(int x) { int[x] my_array; ... this does not compile as x value needs to be known at compile time. The closest to this I can get is: void f(int x) { int[] my_array; my_array.length=