Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread Charles Hixson via Digitalmars-d-learn
On 07/26/2016 12:53 PM, Adam D. Ruppe via Digitalmars-d-learn wrote: On Tuesday, 26 July 2016 at 19:30:35 UTC, Charles Hixson wrote: It looks as if the entire file is stored in memory, which is not at all what I want, but I also can't really believe that's what's going on. It is just mapped t

Re: Remove stuff from a template mixin

2016-07-26 Thread Gorge Jingale via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 22:23:37 UTC, Jerry wrote: On Tuesday, 26 July 2016 at 19:02:32 UTC, Gorge Jingale wrote: I might want to actually use Add internally in B so I can add some elements behind the scenes, I do not want to expose it to the outside world though. There are no way to remo

Re: Why D isn't the next "big thing" already

2016-07-26 Thread Gorge Jingale via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 15:11:00 UTC, llaine wrote: Hi guys, I'm using D since a few month now and I was wondering why people don't jump onto it that much and why it isn't the "big thing" already. Everybody is into javascript nowadays, but IMO even for doing web I found Vibe.d more inte

Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread ketmar via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 16:35:26 UTC, Charles Hixson wrote: That's sort of what I have in mind, but I want to do what in Fortran would be (would have been?) called record I/O, except that I want a file header that specifies a few things like magic number, records allocated, head of free lis

Re: Why D isn't the next "big thing" already

2016-07-26 Thread tsbockman via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 15:11:00 UTC, llaine wrote: I'm using D since a few month now and I was wondering why people don't jump onto it that much and why it isn't the "big thing" already. D2 is under active development. Bugs get fixed, bottlenecks get optimized, and features get added or

Re: Remove stuff from a template mixin

2016-07-26 Thread Jerry via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 19:02:32 UTC, Gorge Jingale wrote: I might want to actually use Add internally in B so I can add some elements behind the scenes, I do not want to expose it to the outside world though. There are no way to remove things from an template directly. But you could howe

Re: Search elemnt in Compile-time Argument List of strings

2016-07-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/26/16 4:58 PM, ParticlePeter wrote: On Tuesday, 26 July 2016 at 20:18:48 UTC, Steven Schveighoffer wrote: void processMember( T, ignore... )() { foreach( member; __traits( allMembers, T )) { // this is a compile-time list, so it's a static foreach. foreach(i, arg; ignore ){ // i

Re: Search elemnt in Compile-time Argument List of strings

2016-07-26 Thread ParticlePeter via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 21:20:18 UTC, ParticlePeter wrote: ... First of all there seems to be a typo, it should not be: else static if(i + 1 == arg.length) ignore must be used instead of arg, as arg.length is the length of a string: else static if(i + 1 == ignore.length) if ignore is

Re: Search elemnt in Compile-time Argument List of strings

2016-07-26 Thread ParticlePeter via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 21:01:19 UTC, Ali Çehreli wrote: On 07/26/2016 01:58 PM, ParticlePeter wrote: On Tuesday, 26 July 2016 at 20:18:48 UTC, Steven Schveighoffer wrote: ... void processMember( T, ignore... )() { foreach( member; __traits( allMembers, T )) { // this is a compile-time l

Re: Why D isn't the next "big thing" already

2016-07-26 Thread phant0m via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 15:11:00 UTC, llaine wrote: Hi guys, I'm using D since a few month now and I was wondering why people don't jump onto it that much and why it isn't the "big thing" already. Everybody is into javascript nowadays, but IMO even for doing web I found Vibe.d more inte

Re: Search elemnt in Compile-time Argument List of strings

2016-07-26 Thread Ali Çehreli via Digitalmars-d-learn
On 07/26/2016 01:58 PM, ParticlePeter wrote: On Tuesday, 26 July 2016 at 20:18:48 UTC, Steven Schveighoffer wrote: ... void processMember( T, ignore... )() { foreach( member; __traits( allMembers, T )) { // this is a compile-time list, so it's a static foreach. foreach(i, arg; ignore ){ //

Re: Search elemnt in Compile-time Argument List of strings

2016-07-26 Thread ParticlePeter via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 20:18:48 UTC, Steven Schveighoffer wrote: ... void processMember( T, ignore... )() { foreach( member; __traits( allMembers, T )) { // this is a compile-time list, so it's a static foreach. foreach(i, arg; ignore ){ // i is the index into the ignore tuple

Re: Search elemnt in Compile-time Argument List of strings

2016-07-26 Thread ParticlePeter via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 20:18:48 UTC, Steven Schveighoffer wrote: ... Thanks a lot for this really cool and detailed explanation (upvoting!). It's a bit weird to work on these compile-time things, but they are so cool when you look at what is available in std.meta and std.traits :) Agr

Re: Check of point inside/outside polygon

2016-07-26 Thread Gorge Jingale via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 19:08:09 UTC, H. S. Teoh wrote: On Tue, Jul 26, 2016 at 06:39:58PM +, Gorge Jingale via Digitalmars-d-learn wrote: On Tuesday, 26 July 2016 at 17:38:43 UTC, Suliman wrote: > I have arbitrary polygon. I need any solution. Performance > is does not matter at curren

Re: Search elemnt in Compile-time Argument List of strings

2016-07-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/26/16 3:30 PM, ParticlePeter wrote: I want to generate one function for any struct data member, but also want to be able to skip few of the members. The first part works, but I have some trouble with the skipping. I pass the struct type and a Compile-time Argument List of strings as templat

Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/26/16 3:30 PM, Charles Hixson via Digitalmars-d-learn wrote: On 07/26/2016 11:31 AM, Steven Schveighoffer via Digitalmars-d-learn wrote: Now, C i/o's buffering may not suit your exact needs. So I don't know how it will perform. You may want to consider mmap which tells the kernel to link

Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 19:30:35 UTC, Charles Hixson wrote: It looks as if the entire file is stored in memory, which is not at all what I want, but I also can't really believe that's what's going on. It is just mapped to virtual memory without actually being loaded into physical memory,

Re: Search elemnt in Compile-time Argument List of strings

2016-07-26 Thread ParticlePeter via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 19:30:18 UTC, ParticlePeter wrote: // Second approach, get warnings for every skipped member // and every line after the return statement: // Warning: statement is not reachable void processMember( T, ignore... )() { foreach( member; __traits( allMembers, T )) {

Search elemnt in Compile-time Argument List of strings

2016-07-26 Thread ParticlePeter via Digitalmars-d-learn
I want to generate one function for any struct data member, but also want to be able to skip few of the members. The first part works, but I have some trouble with the skipping. I pass the struct type and a Compile-time Argument List of strings as template arguments to a template function, lis

Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread Charles Hixson via Digitalmars-d-learn
On 07/26/2016 11:31 AM, Steven Schveighoffer via Digitalmars-d-learn wrote: On 7/26/16 1:57 PM, Charles Hixson via Digitalmars-d-learn wrote: Thanks. Since there isn't any excess overhead I guess I'll use stdio. Buffering, however, isn't going to help at all since I'm doing randomIO. I know t

Re: Check of point inside/outside polygon

2016-07-26 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 26, 2016 at 06:39:58PM +, Gorge Jingale via Digitalmars-d-learn wrote: > On Tuesday, 26 July 2016 at 17:38:43 UTC, Suliman wrote: > > I have arbitrary polygon. I need any solution. Performance is does not > > matter at current moment. > > A polygon is made up of lines. For a point

Re: Remove stuff from a template mixin

2016-07-26 Thread Gorge Jingale via Digitalmars-d-learn
I might want to actually use Add internally in B so I can add some elements behind the scenes, I do not want to expose it to the outside world though.

Remove stuff from a template mixin

2016-07-26 Thread Gorge Jingale via Digitalmars-d-learn
Is there a way to remove functions and fields that a mixin template adds? I use mixin templates to create other types contents, like struct A { mixin Stuff(); } But Sometimes I only want some of the stuff. struct B { mixin Stuff(); @disable Add(); } B is like an A but doesn't have the abilit

Re: Check of point inside/outside polygon

2016-07-26 Thread Gorge Jingale via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 17:38:43 UTC, Suliman wrote: I have arbitrary polygon. I need any solution. Performance is does not matter at current moment. A polygon is made up of lines. For a point to be inside a convex polygon, it must be to the "right" of all the lines with clockwise orienta

Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/26/16 1:57 PM, Charles Hixson via Digitalmars-d-learn wrote: Thanks. Since there isn't any excess overhead I guess I'll use stdio. Buffering, however, isn't going to help at all since I'm doing randomIO. I know that most of the data the system reads from disk is going to end up getting th

Re: Check of point inside/outside polygon

2016-07-26 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 26, 2016 at 05:38:43PM +, Suliman via Digitalmars-d-learn wrote: > I have arbitrary polygon. I need any solution. Performance is does not > matter at current moment. In that case, maybe you'd want to look at: https://en.wikipedia.org/wiki/Vatti_clipping_algorithm Note, ho

Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread Charles Hixson via Digitalmars-d-learn
On 07/26/2016 10:18 AM, Steven Schveighoffer via Digitalmars-d-learn wrote: On 7/26/16 12:58 PM, Charles Hixson via Digitalmars-d-learn wrote: Ranges aren't free, are they? If so then I should probably use stdfile, because that is probably less likely to change than core.stdc.stdio. Do you

Re: Check of point inside/outside polygon

2016-07-26 Thread Suliman via Digitalmars-d-learn
I have arbitrary polygon. I need any solution. Performance is does not matter at current moment.

Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/26/16 12:58 PM, Charles Hixson via Digitalmars-d-learn wrote: Ranges aren't free, are they? If so then I should probably use stdfile, because that is probably less likely to change than core.stdc.stdio. Do you mean slices? When I see "f.rawRead(&item[0 .. 1])" it looks to me as if unnee

Re: question about conditional operator (?:)

2016-07-26 Thread Ali Çehreli via Digitalmars-d-learn
On 07/26/2016 06:41 AM, Richard wrote: From http://wiki.dlang.org/Operator_precedence In case it's useful to others, I explain that table a little bit here (associativity, unordered operators, and the precedence of =>): http://ddili.org/ders/d.en/operator_precedence.html Ali

Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread Charles Hixson via Digitalmars-d-learn
On 07/26/2016 05:31 AM, Steven Schveighoffer via Digitalmars-d-learn wrote: On 7/25/16 9:19 PM, Charles Hixson via Digitalmars-d-learn wrote: On 07/25/2016 05:18 PM, ketmar via Digitalmars-d-learn wrote: On Monday, 25 July 2016 at 18:54:27 UTC, Charles Hixson wrote: Are there reasons why one w

Re: Check of point inside/outside polygon

2016-07-26 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 26, 2016 at 01:32:00PM +, Suliman via Digitalmars-d-learn wrote: > Ideally I need algorithm that can return bool if one polygon > overlapped/intersected by another. But I do not know math. Are you talking about triangles, or general polygons? Are the polygons convex or arbitrary?

Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread Charles Hixson via Digitalmars-d-learn
On 07/25/2016 09:22 PM, ketmar via Digitalmars-d-learn wrote: On Tuesday, 26 July 2016 at 04:05:22 UTC, Charles Hixson wrote: Yes, but I really despise the syntax they came up with. It's probably good if most of your I/O is ranges, but mine hasn't yet ever been. (Combining ranges with random

Why D isn't the next "big thing" already

2016-07-26 Thread llaine via Digitalmars-d-learn
Hi guys, I'm using D since a few month now and I was wondering why people don't jump onto it that much and why it isn't the "big thing" already. Everybody is into javascript nowadays, but IMO even for doing web I found Vibe.d more interesting and efficient than node.js for example. I agre

Re: question about conditional operator (?:)

2016-07-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, July 26, 2016 13:41:39 Richard via Digitalmars-d-learn wrote: > On Tuesday, 26 July 2016 at 13:19:54 UTC, ag0aep6g wrote: > > Operator precedence is different from what you think. `a ? b : > > c = d` means `(a ? b : c) = d`. But you want `a ? b : (c = d)`. > > So you need parentheses ar

Re: question about conditional operator (?:)

2016-07-26 Thread Richard via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 13:19:54 UTC, ag0aep6g wrote: Operator precedence is different from what you think. `a ? b : c = d` means `(a ? b : c) = d`. But you want `a ? b : (c = d)`. So you need parentheses around `p+=1`. Or just go with `if` and `else`. It's clearer anyway. From http://wi

Check of point inside/outside polygon

2016-07-26 Thread Suliman via Digitalmars-d-learn
Ideally I need algorithm that can return bool if one polygon overlapped/intersected by another. But I do not know math. After some googling I found topic on SO[1] about point inside/outside polygon. It's not directly what I need, but as temporal solution would be enough. Maybe somebody alrea

Re: question about conditional operator (?:)

2016-07-26 Thread ag0aep6g via Digitalmars-d-learn
On 07/26/2016 03:09 PM, Richard wrote: if(n%p==0) n/=p; else p+=1; [...] However, if I replace the content of the for loop with the ?: operator, the program is not correct anymore (largestPrimeFactor(4) now returns 3): [...] n%p==0 ? n/=p : p+=1

Re: question about conditional operator (?:)

2016-07-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 13:17:27 UTC, Adam D. Ruppe wrote: (n%p==0) ? n/=p : p+=1 ; And actually, using ?: with /= and += is kinda bizarre. I think you are better off leaving this as if/else since the point of this is the assignment rather than the return value.

Re: question about conditional operator (?:)

2016-07-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 13:09:28 UTC, Richard wrote: n%p==0 ? n/=p : p+=1 ; Try (n%p==0) ? n/=p : p+=1 ; I'm pretty sure the order of operations (precedence rules) puts ?: above ==.

Re: question about conditional operator (?:)

2016-07-26 Thread Cauterite via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 13:09:28 UTC, Richard wrote: Hello all, try using some parentheses: (n%p==0) ? (n/=p) : (p+=1) ;

question about conditional operator (?:)

2016-07-26 Thread Richard via Digitalmars-d-learn
Hello all, I've got a program that correctly computes the largest factor in the prime decomposition of a positive number: * import std.math std.stdio; ulong largestPrimeFactor(ulong n) { for(ulong p=2; p<=sqrt(cast(real)n); ) { i

Re: Expression template

2016-07-26 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 10:35:12 UTC, Etranger wrote: I'll have time 2 months from now as I'm getting married in 2 weeks :) Congratulations!

Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/25/16 9:19 PM, Charles Hixson via Digitalmars-d-learn wrote: On 07/25/2016 05:18 PM, ketmar via Digitalmars-d-learn wrote: On Monday, 25 July 2016 at 18:54:27 UTC, Charles Hixson wrote: Are there reasons why one would use rawRead and rawWrite rather than fread and fwrite when doiing binary

Re: Assert question

2016-07-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 12:13:02 UTC, DLearner wrote: What is the recommended way of identifying which assert has been triggered? If you compile with -g, run the program in a debugger. It will tell you. If you compile and do NOT use -release, the error message automatically printed by t

Re: Assert question

2016-07-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/26/16 8:13 AM, DLearner wrote: Suppose a program contains several points that control should not get to. So each such point is blocked by assert(0). What is the recommended way of identifying which assert has been triggered? Is one allowed anything like 'assert(0,"Crashed at point A");', wh

Assert question

2016-07-26 Thread DLearner via Digitalmars-d-learn
Suppose a program contains several points that control should not get to. So each such point is blocked by assert(0). What is the recommended way of identifying which assert has been triggered? Is one allowed anything like 'assert(0,"Crashed at point A");', where the message goes to stderr?

Re: Expression template

2016-07-26 Thread Etranger via Digitalmars-d-learn
On Saturday, 23 July 2016 at 23:55:44 UTC, ag0aep6g wrote: On 07/23/2016 01:05 PM, Etranger wrote: [...] To avoid the string mixin, you can let VecExpression take an alias of the mixin template (Vec_impl/VecSum_impl) and the list of arguments: [...] Thanks ! that's way much cleaner and t

Re: Expression template

2016-07-26 Thread Etranger via Digitalmars-d-learn
On Sunday, 24 July 2016 at 10:53:41 UTC, Ilya Yaroshenko wrote: On Saturday, 23 July 2016 at 11:05:57 UTC, Etranger wrote: [...] Yes, but it is more complicated in terms of multidimensional and generic abstraction. First we need to finish and test general matrix multiplication [2]. [...]

Re: Static ternary if

2016-07-26 Thread Cauterite via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 00:54:59 UTC, Michael Coulombe wrote: If that's ok, then try out std.traits.Select or std.traits.select: https://dlang.org/phobos/std_traits.html#Select Damn, I looked real hard for that template, I knew it existed. I expected it to be in std.meta though.

Re: Trouble using 'sort'

2016-07-26 Thread Bahman Movaqar via Digitalmars-d-learn
On 07/26/2016 11:42 AM, drug wrote: > Another option is `makeIndex` (std.algorithm.sorting) and then sorting > of that index. That's an interesting option; at least I don't have to touch the range. Thanks. -- Bahman

Re: Trouble using 'sort'

2016-07-26 Thread Bahman Movaqar via Digitalmars-d-learn
On 07/26/2016 10:41 AM, Jonathan M Davis via Digitalmars-d-learn wrote: >> So it may be something about what kind of range I'm passing to `sort`. >> Am I right? > > sort requires a random access range. Without knowing exactly which > algorithms your using, I can't say for sure that that's the prob

Re: Trouble using 'sort'

2016-07-26 Thread drug via Digitalmars-d-learn
26.07.2016 09:11, Jonathan M Davis via Digitalmars-d-learn пишет: It's frequently the case that if you want to sort a range, you have to call array() on it to convert it to an array, and then you can sort the array. - Jonathan M Davis Another option is `makeIndex` (std.algorithm.sorting) and t