Re: How do I properly exit from a D program (outside main)?

2014-09-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 16/09/14 02:06, AsmMan wrote: Neither assert or return will help. Check out this code example: void main() { f(); } void f() { if(!foo) exit(1); do_something(); } If you want to exit the application with exit code 1 then it sounds like something has gone wrong. In that case,

Re: Segfault when casting array of Interface types

2014-09-16 Thread Klaus via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 03:05:57 UTC, Franz wrote: On Tuesday, 16 September 2014 at 03:03:16 UTC, Franz wrote: On Tuesday, 16 September 2014 at 02:21:42 UTC, rcor wrote: I'm back for another round of is this a bug, or am I doing something stupid?. C and D implement interface I, and

Docs for PR

2014-09-16 Thread Ilya Yaroshenko via Digitalmars-d-learn
How generate documentation for phobos PR?

Re: Segfault when casting array of Interface types

2014-09-16 Thread via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 06:27:59 UTC, Klaus wrote: On Tuesday, 16 September 2014 at 03:05:57 UTC, Franz wrote: On Tuesday, 16 September 2014 at 03:03:16 UTC, Franz wrote: On Tuesday, 16 September 2014 at 02:21:42 UTC, rcor wrote: I'm back for another round of is this a bug, or am I

Re: Segfault when casting array of Interface types

2014-09-16 Thread via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 08:39:43 UTC, Marc Schütz wrote: AFACIS there's nothing wrong with his use of casting. It's fine here, because `I` is a base type of `C` and `D`. If it weren't for the arrays, the cast wouldn't even be necessary. I think it's a bug. Correction: AFAIK casting

Re: Function Pointers with Type T

2014-09-16 Thread evilrat via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 01:16:14 UTC, Adam D. Ruppe wrote: bool function(T val1,T val2) ptr=comp!T; Moreover, comp has compile time arguments, so you can't take the address of it without forwarding the arguments. So instead of comp, you use comp!T - passing the T from the outside

Re: Segfault when casting array of Interface types

2014-09-16 Thread rcor via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 08:49:04 UTC, Marc Schütz wrote: On Tuesday, 16 September 2014 at 08:39:43 UTC, Marc Schütz wrote: Whether the compiler should accept that or not is a different question. I guess it should, because if it doesn't, there wouldn't be an easy way to achieve a

Re: Docs for PR

2014-09-16 Thread Robert burner Schadek via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 08:26:57 UTC, Ilya Yaroshenko wrote: How generate documentation for phobos PR? http://wiki.dlang.org/Building_DMD has a section called building the docs. I properly missed something while writing that, but it is good starting point and the rest you will find

Re: Segfault when casting array of Interface types

2014-09-16 Thread rcor via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 06:27:59 UTC, Klaus wrote: is just a horrible way of shortcuting the static typing. You write this thinking that i has to be... and then you complain latter because the cast does not work. D is a strongly typed lang. in your example you use auto because your

Why if(__ctfe)?

2014-09-16 Thread Ilya Yaroshenko via Digitalmars-d-learn
Why not static if(__ctfe) ?

Re: Why if(__ctfe)?

2014-09-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 13:11:50 UTC, Ilya Yaroshenko wrote: Why not static if(__ctfe) ? ctfe is a runtime condition. The function has the same code when run at compile time, it is just being run in a different environment.

Re: Segfault when casting array of Interface types

2014-09-16 Thread via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 11:26:05 UTC, rcor wrote: On Tuesday, 16 September 2014 at 08:49:04 UTC, Marc Schütz wrote: On Tuesday, 16 September 2014 at 08:39:43 UTC, Marc Schütz wrote: Whether the compiler should accept that or not is a different question. I guess it should, because

Re: Why if(__ctfe)?

2014-09-16 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 13:28:17 UTC, Rene Zwanenburg wrote: On Tuesday, 16 September 2014 at 13:17:28 UTC, Adam D. Ruppe wrote: On Tuesday, 16 September 2014 at 13:11:50 UTC, Ilya Yaroshenko wrote: Why not static if(__ctfe) ? ctfe is a runtime condition. The function has the same

Is there a function that reads the entire contents of a std.stdio.File?

2014-09-16 Thread Jay via Digitalmars-d-learn
all the functions/methods i've come across so far deal with either streams or just file names (like std.file.read) and there doesn't seem to be a way to wrap a std.stdio.File in a stream (or is there?). i need a function that takes a std.stdio.File and returns a string or byte array.

Re: Is there a function that reads the entire contents of a std.stdio.File?

2014-09-16 Thread via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 14:37:06 UTC, Jay wrote: all the functions/methods i've come across so far deal with either streams or just file names (like std.file.read) and there doesn't seem to be a way to wrap a std.stdio.File in a stream (or is there?). i need a function that takes a

Re: Is there a function that reads the entire contents of a std.stdio.File?

2014-09-16 Thread Daniel Kozak via Digitalmars-d-learn
V Tue, 16 Sep 2014 14:37:05 + Jay via Digitalmars-d-learn digitalmars-d-learn@puremagic.com napsáno: all the functions/methods i've come across so far deal with either streams or just file names (like std.file.read) and there doesn't seem to be a way to wrap a std.stdio.File in a stream

Re: Is there a function that reads the entire contents of a std.stdio.File?

2014-09-16 Thread Jay via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 14:43:10 UTC, Marc Schütz wrote: You could try `std.mmfile.MmFile`, it has a constructor that takes a `File`, but only on Linux: http://dlang.org/phobos/std_mmfile.html https://github.com/D-Programming-Language/phobos/blob/master/std/mmfile.d#L77-L79 does it

Re: Is there a function that reads the entire contents of a std.stdio.File?

2014-09-16 Thread Jay via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 14:49:08 UTC, Daniel Kozak via Digitalmars-d-learn wrote: You can use rawRead: http://dlang.org/phobos/std_stdio.html#.File.rawRead for that i need to know the size of the contents. is there a function that does that for me? i'm looking for something like

Re: Is there a function that reads the entire contents of a std.stdio.File?

2014-09-16 Thread Jay via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 15:03:05 UTC, Jay wrote: and it shouldn't matter whether the File instance represents a regular file or a pipe/stream. i meant pipe/socket.

switch statement exiting a void function

2014-09-16 Thread Jonathan via Digitalmars-d-learn
Here's the setup, I have a function void main { ... } The main method parses input (via std.getopt) and calls one of three void-return-type functions. The program's three options correspond to significantly different initialization options. In the code we then have: enum RunOpt

Re: switch statement exiting a void function

2014-09-16 Thread bearophile via Digitalmars-d-learn
Jonathan: This is not intended. Note that calling return; after funi(...) makes everything work. However, it feels like I'm doing something wrong here? Try: enum RunOpt { opt1, opt2, opt3 } // No semicolon here final switch (option) with (RunOpt) { case opt1: fun1(...); break;

Re: Is there a function that reads the entire contents of a std.stdio.File?

2014-09-16 Thread via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 14:59:45 UTC, Jay wrote: On Tuesday, 16 September 2014 at 14:43:10 UTC, Marc Schütz wrote: You could try `std.mmfile.MmFile`, it has a constructor that takes a `File`, but only on Linux: http://dlang.org/phobos/std_mmfile.html

sort using delegate as predicate

2014-09-16 Thread via Digitalmars-d-learn
The following code does not compile, because the custom predicate of std.algorithm.sort is a template parameter, and therefore can only be a function, but not a delegate. In C++, there is a variant of sort taking a function-object as a second (run-time) parameter, but phobos does not seems to

Re: sort using delegate as predicate

2014-09-16 Thread Justin Whear via Digitalmars-d-learn
On Tue, 16 Sep 2014 16:19:10 +, Simon Bürger wrote: The following code does not compile, because the custom predicate of std.algorithm.sort is a template parameter, and therefore can only be a function, but not a delegate. In C++, there is a variant of sort taking a function-object as a

Re: sort using delegate as predicate

2014-09-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Sep 16, 2014 at 04:19:10PM +, via Digitalmars-d-learn wrote: The following code does not compile, because the custom predicate of std.algorithm.sort is a template parameter, and therefore can only be a function, but not a delegate. What makes you think so? Template parameters

Re: sort using delegate as predicate

2014-09-16 Thread via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 16:27:46 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Tue, Sep 16, 2014 at 04:19:10PM +, via Digitalmars-d-learn wrote: The following code does not compile, because the custom predicate of std.algorithm.sort is a template parameter, and therefore can

Re: How to pass a member function/delegate into a mixin template?

2014-09-16 Thread 岩倉 澪
On Monday, 15 September 2014 at 21:37:50 UTC, John Colvin wrote: would this work for you? alias is the usual way of taking a function as a template parameter. mixin template EventListener(alias slot) Ah, thanks for the help! That works great. :)

Re: Is there a function that reads the entire contents of a std.stdio.File?

2014-09-16 Thread Ali Çehreli via Digitalmars-d-learn
On 09/16/2014 07:37 AM, Jay wrote: all the functions/methods i've come across so far deal with either streams or just file names (like std.file.read) and there doesn't seem to be a way to wrap a std.stdio.File in a stream (or is there?). i need a function that takes a std.stdio.File and returns

Re: sort using delegate as predicate

2014-09-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Sep 16, 2014 at 04:38:04PM +, via Digitalmars-d-learn wrote: On Tuesday, 16 September 2014 at 16:27:46 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Tue, Sep 16, 2014 at 04:19:10PM +, via Digitalmars-d-learn wrote: The following code does not compile, because the custom

Re: dub can't read files from cache

2014-09-16 Thread Ruslan via Digitalmars-d-learn
Note. ╨а╤Г╤Б╨╗╨░╨╜ is a cyrillic word. That should not affect because dub only displays so.

Re: switch statement exiting a void function

2014-09-16 Thread Jonathan via Digitalmars-d-learn
Try: enum RunOpt { opt1, opt2, opt3 } // No semicolon here final switch (option) with (RunOpt) { case opt1: fun1(...); break; case opt2: fun2(...); break; case opt3: fun3(...); break; } Bye, bearophile My hero.

Re: Function Pointers with Type T

2014-09-16 Thread amparacha via Digitalmars-d-learn
Thanks Adam you saved me from alot.Just one more question how can I compare two arguments of type T. On Tuesday, 16 September 2014 at 01:16:14 UTC, Adam D. Ruppe wrote: You can get the code to compile with two changes: bool function(T)(T val1,T val2) ptr=comp; should be: bool function(T

Re: Function Pointers with Type T

2014-09-16 Thread amparacha via Digitalmars-d-learn
Thanks its the right help at right time. On Tuesday, 16 September 2014 at 09:13:38 UTC, evilrat wrote: On Tuesday, 16 September 2014 at 01:16:14 UTC, Adam D. Ruppe wrote: bool function(T val1,T val2) ptr=comp!T; Moreover, comp has compile time arguments, so you can't take the address of it

Re: Function Pointers with Type T

2014-09-16 Thread amparacha via Digitalmars-d-learn
Thankx On Tuesday, 16 September 2014 at 01:21:57 UTC, ketmar via Digitalmars-d-learn wrote: On Tue, 16 Sep 2014 01:09:27 + amparacha via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: first change: bool function(T)(T val1,T val2) ptr=comp; to auto ptr = comp!T; second

Re: Function Pointers with Type T

2014-09-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 17:32:02 UTC, amparacha wrote: Thanks Adam you saved me from alot.Just one more question how can I compare two arguments of type T. If you want to compare the values, just use them like regular variables. If you want to compare the types, use: static

Re: Segfault when casting array of Interface types

2014-09-16 Thread rcor via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 14:13:48 UTC, Marc Schütz wrote: On Tuesday, 16 September 2014 at 11:26:05 UTC, rcor wrote: Is to! creating a new array of pointers while cast isn't? This isn't a performance critical section and it's not a huge array, so I ask mostly out of curiosity. Yes,

Re: Is there a function that reads the entire contents of a std.stdio.File?

2014-09-16 Thread Jay via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 16:54:17 UTC, Ali Çehreli wrote: On 09/16/2014 07:37 AM, Jay wrote: all the functions/methods i've come across so far deal with either streams or just file names (like std.file.read) and there doesn't seem to be a way to wrap a std.stdio.File in a stream (or is

Re: Is there a function that reads the entire contents of a std.stdio.File?

2014-09-16 Thread Justin Whear via Digitalmars-d-learn
On Tue, 16 Sep 2014 14:37:05 +, Jay wrote: all the functions/methods i've come across so far deal with either streams or just file names (like std.file.read) and there doesn't seem to be a way to wrap a std.stdio.File in a stream (or is there?). i need a function that takes a

compile automation, makefile, or whatever?

2014-09-16 Thread K.K. via Digitalmars-d-learn
Hey I have a quick question: Does D have it's own version of makefiles or anything (preferably simpler)? So instead of typing in PowerShell dmd file1.d file2.d lib\foo.lib -Isrc\ . I could just type most of that into a file and then just type dmd file.X I've seen some people make really

Re: Is there a function that reads the entire contents of a std.stdio.File?

2014-09-16 Thread Jay via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 18:42:42 UTC, Justin Whear wrote: The short answer is no. I usually use something like this: // Lazy auto stream = stdin.byChunk(4096).joiner(); You can make it eager by tacking a `.array` on the end. Functions used are from std.stdio,

Re: compile automation, makefile, or whatever?

2014-09-16 Thread Cliff via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 19:00:05 UTC, K.K. wrote: Hey I have a quick question: Does D have it's own version of makefiles or anything (preferably simpler)? So instead of typing in PowerShell dmd file1.d file2.d lib\foo.lib -Isrc\ . I could just type most of that into a file and then

Re: core.exception.UnicodeException@src\rt\util\utf.d(400): illegal UTF-16 value

2014-09-16 Thread notna via Digitalmars-d-learn
Thanks Ali. As always, your examples and explanations are amazingly clear and easy to understand. On Monday, 15 September 2014 at 23:57:59 UTC, Ali Çehreli wrote: You must make use of the returned value to slice your wstring. Something like this (not compiled): auto actualLength =

Re: core.exception.UnicodeException@src\rt\util\utf.d(400): illegal UTF-16 value

2014-09-16 Thread notna via Digitalmars-d-learn
Thanks AsmMan, Found http://msdn.microsoft.com/en-us/library/windows/desktop/ms724432%28v=vs.85%29.aspx and with your help, now understand :) The syntax below prints a blank after my username, so the slice seems a bit too long :O So my final solution looks like: module main; import

Re: compile automation, makefile, or whatever?

2014-09-16 Thread K.K. via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 19:26:29 UTC, Cliff wrote: I want to say somewhere on the forums are some descriptions of using CMake for this. Might try searching for that. Yeah I just looked up the CMake thing. It definitely seems worth playing with, though I'm not really sure how

Re: compile automation, makefile, or whatever?

2014-09-16 Thread Cliff via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 20:29:12 UTC, K.K. wrote: On Tuesday, 16 September 2014 at 19:26:29 UTC, Cliff wrote: I want to say somewhere on the forums are some descriptions of using CMake for this. Might try searching for that. Yeah I just looked up the CMake thing. It definitely seems

Re: compile automation, makefile, or whatever?

2014-09-16 Thread K.K. via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 20:31:33 UTC, Cliff wrote: Out of curiosity, why are you not using dub (on the command-line)? I'm not against using it or anything, but I've found that it didn't help me significantly nor did I have the patience to figure out it's whole set of issues, D by

Re: compile automation, makefile, or whatever?

2014-09-16 Thread Cliff via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 20:45:29 UTC, K.K. wrote: On Tuesday, 16 September 2014 at 20:31:33 UTC, Cliff wrote: Out of curiosity, why are you not using dub (on the command-line)? I'm not against using it or anything, but I've found that it didn't help me significantly nor did I have

Re: compile automation, makefile, or whatever?

2014-09-16 Thread Andrei Amatuni via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 19:00:05 UTC, K.K. wrote: Hey I have a quick question: Does D have it's own version of makefiles or anything (preferably simpler)? So instead of typing in PowerShell dmd file1.d file2.d lib\foo.lib -Isrc\ . I could just type most of that into a file and then

Re: compile automation, makefile, or whatever?

2014-09-16 Thread K.K. via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 20:53:08 UTC, Cliff wrote: Would you be willing to provide some more detail on what about it you didn't like (errors, missing features, etc.)? I ask because build systems are a particular interest of mine and I have projects in this area which can always use

Re: compile automation, makefile, or whatever?

2014-09-16 Thread K.K. via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 20:57:20 UTC, Andrei Amatuni wrote: Have you tried - http://dlang.org/rdmd.html only a tiny bit... I've haven't quite figured rdmd yet :\ I'm actually trying it out right now.

Re: compile automation, makefile, or whatever?

2014-09-16 Thread Cliff via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 21:05:18 UTC, K.K. wrote: On Tuesday, 16 September 2014 at 20:53:08 UTC, Cliff wrote: Would you be willing to provide some more detail on what about it you didn't like (errors, missing features, etc.)? I ask because build systems are a particular interest of

Re: compile automation, makefile, or whatever?

2014-09-16 Thread K.K. via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 21:17:19 UTC, Cliff wrote: On Tuesday, 16 September 2014 at 21:05:18 UTC, K.K. wrote: On Tuesday, 16 September 2014 at 20:53:08 UTC, Cliff wrote: Would you be willing to provide some more detail on what about it you didn't like (errors, missing features, etc.)?

Re: compile automation, makefile, or whatever?

2014-09-16 Thread bachmeier via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 20:31:33 UTC, Cliff wrote: On Tuesday, 16 September 2014 at 20:29:12 UTC, K.K. wrote: On Tuesday, 16 September 2014 at 19:26:29 UTC, Cliff wrote: I want to say somewhere on the forums are some descriptions of using CMake for this. Might try searching for that.

exporting analysispoint labels into symbol tables

2014-09-16 Thread Jay Norwood via Digitalmars-d-learn
I have a use case that requires repeating performance measurements of blocks of code that do not coincide with function start and stop. For example, a function will be calling several sub-operations, and I need to measure the execution from the call statement until the execution of the

Code doesn't work - why?

2014-09-16 Thread Robin via Digitalmars-d-learn
Hello, I came back to D after a longer break and just wanted to set up a small project to further get in contact with this language. However, it seems that the codes which simply shall simulate a deterministic finit automaton do not work correctly. CODE --- struct DeterministicState {

Re: Code doesn't work - why?

2014-09-16 Thread Ali Çehreli via Digitalmars-d-learn
On 09/16/2014 09:08 PM, Robin wrote: struct DeterministicState { Structs are value types. When they are copied, the mutations that you expect may be happening on a copy. I don't understand what exactly should happen but the following changes produce at least a different output. :) 1)