Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-26 Thread Jack Applegame via Digitalmars-d-learn
On Monday, 16 January 2017 at 14:47:23 UTC, Era Scarecrow wrote: static char[1024*4] buffer; //4k reusable buffer, NOT thread safe Maybe I'm wrong, but I think it's thread safe. Because static mutable non-shared variables are stored in TLS.

Re: D idom for removing array elements

2017-01-26 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 26 January 2017 at 23:10:02 UTC, albert-j wrote: On Thursday, 26 January 2017 at 13:21:38 UTC, Dukc wrote: import std.stdio, std.algorithm, std.range, std.array; int[] a = [1, 2, 3, 4, 5, 6, 7, 4]; int[] b = [3, 4, 6]; auto sortedB = sort(b.dup); auto c = a . filter!(i =>

Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-26 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 17 January 2017 at 11:40:15 UTC, Nestor wrote: Thanks, but unfortunately this function does not produce proper UTF8 strings, as a matter of fact the output even starts with the BOM. Also it doesn't handle CRLF, and even for LF terminated lines it doesn't seem to work for lines

Re: D idom for removing array elements

2017-01-26 Thread albert-j via Digitalmars-d-learn
On Thursday, 26 January 2017 at 13:21:38 UTC, Dukc wrote: import std.stdio, std.algorithm, std.range, std.array; int[] a = [1, 2, 3, 4, 5, 6, 7, 4]; int[] b = [3, 4, 6]; auto sortedB = sort(b.dup); auto c = a . filter!(i => !sortedB.contains(i)) . array ; assert(c == [1, 2, 5, 7]); If

Re: When I should create structures with new keywords?

2017-01-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 26 January 2017 at 19:30:54 UTC, Suliman wrote: But I still not understand where the data is location in first variant? It is stored in the file itself. The File struct is pretty small, it just provides access to the contents of the file, it doesn't actually hold that content

When I should create structures with new keywords?

2017-01-26 Thread Suliman via Digitalmars-d-learn
In the past I asked Adam about when I should use keyword `new` with structures and got next answer: "The File in the first one is put on the stack as a reference counted local object whereas the second one would be on the garbage collected heap, which often isn't what you want for files since

Re: D idom for removing array elements

2017-01-26 Thread Jordan Wilson via Digitalmars-d-learn
On Thursday, 26 January 2017 at 08:22:09 UTC, albert-j wrote: What is the D idiom for removing array elements that are present in another array? Is this the right/fastest way? int[] a = [1, 2, 3, 4, 5, 6, 7, 4]; int[] b = [3, 4, 6]; auto c = a.remove!(x => b.canFind(x)); assert(c == [1, 2, 5,

Re: dub subpackage output to shared lib not working

2017-01-26 Thread Tofu Ninja via Digitalmars-d-learn
On Thursday, 26 January 2017 at 19:01:41 UTC, Tofu Ninja wrote: Actually.. if I do dub describe on the root package it lists both the exe and the lib as targets but the build settings for the lib has "targetType": 6 which according to dub/source/dub/compilers/buildsettings.d is

Re: dub subpackage output to shared lib not working

2017-01-26 Thread Tofu Ninja via Digitalmars-d-learn
On Thursday, 26 January 2017 at 18:26:27 UTC, Tofu Ninja wrote: On Thursday, 26 January 2017 at 18:10:12 UTC, Tofu Ninja wrote: On Thursday, 26 January 2017 at 18:00:57 UTC, Tofu Ninja wrote: Is this not doable? I guess an alternative question, is there any way to have multiple binaries(an

Re: Bug in documentation or misunderstanding it?

2017-01-26 Thread Suliman via Digitalmars-d-learn
On Thursday, 26 January 2017 at 18:42:29 UTC, Suliman wrote: On Thursday, 26 January 2017 at 17:52:24 UTC, H. S. Teoh wrote: On Thu, Jan 26, 2017 at 05:38:59PM +, Suliman via Digitalmars-d-learn wrote: I read docs and can't understand what's wrong. Or I am do not understand it, or there is

Re: Bug in documentation or misunderstanding it?

2017-01-26 Thread Suliman via Digitalmars-d-learn
On Thursday, 26 January 2017 at 17:52:24 UTC, H. S. Teoh wrote: On Thu, Jan 26, 2017 at 05:38:59PM +, Suliman via Digitalmars-d-learn wrote: I read docs and can't understand what's wrong. Or I am do not understand it, or there is come mistake. Let's look at function

Re: dub subpackage output to shared lib not working

2017-01-26 Thread Tofu Ninja via Digitalmars-d-learn
On Thursday, 26 January 2017 at 18:10:12 UTC, Tofu Ninja wrote: On Thursday, 26 January 2017 at 18:00:57 UTC, Tofu Ninja wrote: Is this not doable? I guess an alternative question, is there any way to have multiple binaries(an executable and a bunch of shared libs) built from a single dub

Re: dub subpackage output to shared lib not working

2017-01-26 Thread Tofu Ninja via Digitalmars-d-learn
On Thursday, 26 January 2017 at 18:00:57 UTC, Tofu Ninja wrote: Is this not doable? I guess an alternative question, is there any way to have multiple binaries(an executable and a bunch of shared libs) built from a single dub package? Or should I just give up on trying to use dub for

Re: dub subpackage output to shared lib not working

2017-01-26 Thread Tofu Ninja via Digitalmars-d-learn
On Sunday, 22 January 2017 at 08:16:49 UTC, Tofu Ninja wrote: Trying to get a dub sub package to output as a shared lib but for some reason I can only get it to output as a static lib. dub.json --- { "name": "tofueng", "targetType": "executable", "targetPath" : "game",

Re: Bug in documentation or misunderstanding it?

2017-01-26 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 26, 2017 at 05:38:59PM +, Suliman via Digitalmars-d-learn wrote: > I read docs and can't understand what's wrong. Or I am do not understand it, > or there is come mistake. > > Let's look at function https://dlang.org/phobos/std_stdio.html#.File.byLine > > auto byLine(Terminator =

Re: Bug in documentation or misunderstanding it?

2017-01-26 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 26 January 2017 at 17:38:59 UTC, Suliman wrote: I read docs and can't understand what's wrong. Or I am do not understand it, or there is come mistake. [...] You have to import typecons.

Re: D idom for removing array elements

2017-01-26 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 26 January 2017 at 11:44:27 UTC, Nicholas Wilson wrote: On Thursday, 26 January 2017 at 08:22:09 UTC, albert-j wrote: What is the D idiom for removing array elements that are present in another array? Is this the right/fastest way? int[] a = [1, 2, 3, 4, 5, 6, 7, 4]; int[] b =

Bug in documentation or misunderstanding it?

2017-01-26 Thread Suliman via Digitalmars-d-learn
I read docs and can't understand what's wrong. Or I am do not understand it, or there is come mistake. Let's look at function https://dlang.org/phobos/std_stdio.html#.File.byLine auto byLine(Terminator = char, Char = char)(KeepTerminator keepTerminator = No.keepTerminator, Terminator

Re: Trying to understand multidimensional arrays in D

2017-01-26 Thread Ivan Kazmenko via Digitalmars-d-learn
On Thursday, 26 January 2017 at 05:20:07 UTC, Profile Anaysis wrote: (On the contrary, declarations in C or C++ looks rather unintuitive from this perspective: `T a[4][5][6]` is means that `a` is an array of 4 arrays of 5 arrays of 6 arrays of `T`. Note how we have to read left-to-right but

Re: D idom for removing array elements

2017-01-26 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 26 January 2017 at 08:22:09 UTC, albert-j wrote: What is the D idiom for removing array elements that are present in another array? Is this the right/fastest way? int[] a = [1, 2, 3, 4, 5, 6, 7, 4]; int[] b = [3, 4, 6]; auto c = a.remove!(x => b.canFind(x)); assert(c == [1, 2, 5,

Re: Trying to understand multidimensional arrays in D

2017-01-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, January 26, 2017 05:44:04 Profile Anaysis via Digitalmars-d- learn wrote: > I am using static arrays because the size of the matrix is fixed. > I need to allocate them though because that is what my > matrix_history contains. If I understood correctly, you want a dynamic array of

Re: Trying to understand multidimensional arrays in D

2017-01-26 Thread Mike Parker via Digitalmars-d-learn
Sorry. I mistyped some of my examples. Obviously dropped some news: auto a = new int[](4); auto b = new int[][](4); And the static arrays should be: int[4] c; int[][4] d; And I would also like managed to overlook there is no static array in sight here: auto y = new int[1][2][][](3,4); The

Re: Trying to understand multidimensional arrays in D

2017-01-26 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 26 January 2017 at 05:50:03 UTC, Profile Anaysis wrote: It is inconsistent with dynamic arrays and mixing them creates a mess in the order of indices. I best someone was asleep at the wheel when programming the code for static arrays. (probably someone different than who

D idom for removing array elements

2017-01-26 Thread albert-j via Digitalmars-d-learn
What is the D idiom for removing array elements that are present in another array? Is this the right/fastest way? int[] a = [1, 2, 3, 4, 5, 6, 7, 4]; int[] b = [3, 4, 6]; auto c = a.remove!(x => b.canFind(x)); assert(c == [1, 2, 5, 7]);

Re: Why is [0] @safer than array.ptr?

2017-01-26 Thread Dukc via Digitalmars-d-learn
On Wednesday, 25 January 2017 at 22:59:55 UTC, Jonathan M Davis wrote: So, yes, if all you're planning to do is look at the pointer to the first element in the array, then [0] is safer, but odds are quite low that that's actually what you're going to do, and in all of the other cases, you