Re: print function

2016-02-05 Thread cy via Digitalmars-d-learn
On Friday, 5 February 2016 at 12:35:14 UTC, Artur Skawina wrote: D's std lib implementations are sometimes really awful, but in this case it's not actually that bad: print("hi","there"); -> fwrite("hi", 1, 2, 0x7ff68d0cb640) = 2 fwrite(" ", 1, 1,

What's going to replace std.stream?

2016-02-05 Thread cy via Digitalmars-d-learn
Let's say I have a socket, and a file, and I want to send the contents of that file to the socket. What's the best way to do that? Yes I'm aware that in Linux, you can use a combination of a pipe and splice(2) to keep all buffers kernel side for that, but I was thinking more generally. The

Re: Is this a bug in std.typecons.Tuple.slice?

2016-02-05 Thread Marco Leise via Digitalmars-d-learn
Am Sat, 06 Feb 2016 04:28:17 + schrieb tsbockman : > On Friday, 5 February 2016 at 19:16:11 UTC, Marco Leise wrote: > >> > 1. Removing 'ref' from the return type > > > > Must happen. 'ref' only worked because of the reinterpreting > > cast which doesn't work in

Re: Template to create a type and instantiate it

2016-02-05 Thread Marco Leise via Digitalmars-d-learn
Mixin templates is the way to go if you want something new on every use of the template. Otherwise using the template multiple times with the same arguments will always give you the first instance. -- Marco

Re: Template to create a type and instantiate it

2016-02-05 Thread cy via Digitalmars-d-learn
On Saturday, 6 February 2016 at 06:39:27 UTC, Marco Leise wrote: using the template multiple times with the same arguments will always give you the first instance. Hmm, consider that the argument was a particular line of code though, and that's not likely to repeat. I didn't test what would

Re: Overloading free functions & run-time dispatch based on parameter types

2016-02-05 Thread Marc Schütz via Digitalmars-d-learn
Does the following help? import std.algorithm.comparison : castSwitch; import std.stdio; class A { } class B : A { } class C : A { } auto foo_impl(B b) { writeln("called foo(B)"); } auto foo_impl(C c) { writeln("called foo(C)"); } auto foo(A a) { return a.castSwitch!( (B

Re: What reasons are known a thread stops suddenly?

2016-02-05 Thread Kagamin via Digitalmars-d-learn
https://dlang.org/phobos/core_thread.html#.Thread.join

Re: What reasons are known a thread stops suddenly?

2016-02-05 Thread Kagamin via Digitalmars-d-learn
Yep, munching an Error by default is pretty nasty.

Re: Is this a bug in std.typecons.Tuple.slice?

2016-02-05 Thread Marco Leise via Digitalmars-d-learn
Am Fri, 05 Feb 2016 05:31:15 + schrieb Saurabh Das : > On Friday, 5 February 2016 at 05:18:01 UTC, Saurabh Das wrote: > [...] > > Apologies for spamming. This is an improved implementation: > > @property > Tuple!(sliceSpecs!(from, to)) slice(size_t

Need some help about error that I don't understand

2016-02-05 Thread Uranuz via Digitalmars-d-learn
In my custom multithreaded web-server (non vibe-based) I got error that is strange for me. I've was looking for a reason running app under GDB, but I don't understand how to interpret what I've got. It's interesting that it fails (without any error or segfault message) in the case when null

Re: What reasons are known a thread stops suddenly?

2016-02-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/5/16 12:06 PM, Kagamin wrote: https://dlang.org/phobos/core_thread.html#.Thread.join Yeah, but in the meantime, the thread state is not cleaned up, and it's in the same memory space as everywhere else. I don't see why if you have an out-of-bounds error in the main thread, it should

Re: Need some help about error that I don't understand

2016-02-05 Thread Uranuz via Digitalmars-d-learn
On Friday, 5 February 2016 at 17:39:55 UTC, Uranuz wrote: In my custom multithreaded web-server (non vibe-based) I got error that is strange for me. I've was looking for a reason running app under GDB, but I don't understand how to interpret what I've got. It's interesting that it fails

Re: What reasons are known a thread stops suddenly?

2016-02-05 Thread Ali Çehreli via Digitalmars-d-learn
On 02/04/2016 10:41 PM, tcak wrote: > On Friday, 5 February 2016 at 06:23:09 UTC, Daniel Kozak wrote: >> V Fri, 05 Feb 2016 03:47:40 + >> tcak via Digitalmars-d-learn >> napsáno: >> >>> [...] >> >> Did you try catch Throwable instead of Exception? I was

Re: Proper Use of Assert and Enforce

2016-02-05 Thread Suliman via Digitalmars-d-learn
It is purely a way to make throwing an exception use a syntax similar to assert and save a line of code. if(!condition) throw new Exception(msg); becomes enforce(condition, msg); So enforce is just macros on top of: if(!condition) throw new Exception(msg); ?

Re: Detecting exception unwinding

2016-02-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Friday, 5 February 2016 at 07:31:24 UTC, cy wrote: I think you might be talking about two very different concepts here. Unwinding only happens within the context of a certain scope. The object itself is the scope (RAII). If you can test for "uncaught_exceptions" you can implement the

Re: Proper Use of Assert and Enforce

2016-02-05 Thread Ali Çehreli via Digitalmars-d-learn
On 02/05/2016 12:01 AM, Suliman wrote: It is purely a way to make throwing an exception use a syntax similar to assert and save a line of code. if(!condition) throw new Exception(msg); becomes enforce(condition, msg); So enforce is just macros on top of: if(!condition) throw new

Custom hash table key is const, how to call dtors?

2016-02-05 Thread Marco Leise via Digitalmars-d-learn
Usually I want the keys to be declared "immutable" to signal that their content must not change in order to provide stable hashes. But when you remove items from the table you need to call a const/immutable dtor that needs to be written for everything that can be a hash table key. What do you put

Re: Overloading free functions & run-time dispatch based on parameter types

2016-02-05 Thread Robert M. Münch via Digitalmars-d-learn
On 2016-02-05 15:23:53 +, Marc Schütz said: Does the following help? ... I thought about it too, but I need it to work with more then one parameter, so I tried this which doesn't work: Value nativePlus(Value a, Value b){ // @@ not working, runtime exception castSwitch!( (IntV a)

Re: Proper Use of Assert and Enforce

2016-02-05 Thread Minas Mina via Digitalmars-d-learn
On Wednesday, 14 March 2012 at 05:44:24 UTC, Chris Pons wrote: I'm new, and trying to incorporate assert and enforce into my program properly. My question revolves around, the fact that assert is only evaluated when using the debug switch. I read that assert throws a more serious exception

Re: Why this code can't take advantage from CTFE?

2016-02-05 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 22:45:47 UTC, Timon Gehr wrote: I would use enum forceCTFE(alias expr)=expr; though. With alias it won't force compile-time evaluation of expressions that can be interpreted as symbols. I've a code that build a JSON object using a wrapper over std.json.

Re: Why this code can't take advantage from CTFE?

2016-02-05 Thread Luis via Digitalmars-d-learn
On Friday, 5 February 2016 at 09:36:37 UTC, Andrea Fontana wrote: On Wednesday, 3 February 2016 at 22:45:47 UTC, Timon Gehr wrote: I would use enum forceCTFE(alias expr)=expr; though. With alias it won't force compile-time evaluation of expressions that can be interpreted as symbols. I've a

Re: Proper Use of Assert and Enforce

2016-02-05 Thread Suliman via Digitalmars-d-learn
On Friday, 5 February 2016 at 08:45:00 UTC, Minas Mina wrote: On Wednesday, 14 March 2012 at 05:44:24 UTC, Chris Pons wrote: I'm new, and trying to incorporate assert and enforce into my program properly. My question revolves around, the fact that assert is only evaluated when using the

Re: print function

2016-02-05 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 5 February 2016 at 07:04:27 UTC, cy wrote: Mind if I elaborate on this a bit? If that is unrolled, I understand it will unroll into several calls to write, as in print("1","2","3") => write("1"," ");write("2"," ");write("3","\n"); Up to here, yes. And presumably, write()

Re: Why this code can't take advantage from CTFE?

2016-02-05 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 5 February 2016 at 09:49:38 UTC, Luis wrote: Reading/parsing a JSON or a XML using std.json / std.xml could be done on CTFE ? parseJSON() from std.json doesn't work with CTFE. But I can build objects with with my code that works over std.json. So if you convert (with mixins) {

Re: Proper Use of Assert and Enforce

2016-02-05 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 5 February 2016 at 08:45:00 UTC, Minas Mina wrote: Use assertions when a variable's value should not depend on external factors. For example, let's say you want to write a square root function. The input must be >= 0, and because this depends on external factors (e.g. user input),

Overloading free functions & run-time dispatch based on parameter types

2016-02-05 Thread Robert M. Münch via Digitalmars-d-learn
From the docs: class A { } class B : A { } class C : B { } void foo(A); void foo(B); void test() { C c; foo(c); // calls foo(B) } I need the other way around. So, at runtime I get an A and depending on it's dynamic type, I would like to get the correct foo() called. class A { }

Re: Proper Use of Assert and Enforce

2016-02-05 Thread bachmeier via Digitalmars-d-learn
On Friday, 5 February 2016 at 09:50:43 UTC, Suliman wrote: Will asserts stay after compilation in release mode? No. The only assert that remains in release mode is assert(false) or assert(0) as a way to identify that you've reached a piece of code that shouldn't be executed.

Re: print function

2016-02-05 Thread ixid via Digitalmars-d-learn
On Thursday, 4 February 2016 at 22:13:36 UTC, Ola Fosheim Grøstad wrote: Well, it is probably not the best point in time to have absolute beginners use D anyway. That is a ridiculous thing to say and a great way of ensuring a language dies. Good starting resources help everyone.

Re: Overloading free functions & run-time dispatch based on parameter types

2016-02-05 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 5 February 2016 at 10:54:27 UTC, Robert M. Münch wrote: From the docs: class A { } class B : A { } class C : B { } void foo(A); void foo(B); [...] sounds like foo should just be a method in the class rather than a free function

Re: print function

2016-02-05 Thread Artur Skawina via Digitalmars-d-learn
On 02/05/16 08:04, cy via Digitalmars-d-learn wrote: > On Thursday, 4 February 2016 at 15:32:48 UTC, Artur Skawina wrote: >>void print(A...)(A a) { >> foreach (N, ref e; a) >> write(e, N==A.length-1?"\n":" "); >>} > >>> will be unrolled at compile time > > Mind if I

Re: print function

2016-02-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Friday, 5 February 2016 at 12:35:14 UTC, Artur Skawina wrote: call used to print diagnostics. What I saw made me never use or look at D's std lib again. Except for meta programing and toy/example programs where it doesn't matter. What do you use instead? A buffer and Posix write() and

Re: Overloading free functions & run-time dispatch based on parameter types

2016-02-05 Thread Robert M. Münch via Digitalmars-d-learn
On 2016-02-05 11:10:36 +, Nicholas Wilson said: sounds like foo should just be a method in the class rather than a free function In my particular case I want to keep some stuff outside of claases. -- Robert M. Münch http://www.saphirion.com smarter | better | faster

Re: print function

2016-02-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Friday, 5 February 2016 at 07:04:27 UTC, cy wrote: tl;dr speed demons use std.stream.InputStream.read() whenever you can, and std.stream.OutputStream.write() its result. Isn't std.stream deprecated?

Re: print function

2016-02-05 Thread Artur Skawina via Digitalmars-d-learn
On 02/05/16 14:38, Ola Fosheim Grøstad via Digitalmars-d-learn wrote: > On Friday, 5 February 2016 at 12:35:14 UTC, Artur Skawina wrote: >> call used to print diagnostics. What I saw made me never use or look at D's >> std lib again. Except for meta programing and toy/example programs where it

Re: What reasons are known a thread stops suddenly?

2016-02-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/5/16 2:59 AM, Ali Çehreli wrote: On 02/04/2016 10:41 PM, tcak wrote: > On Friday, 5 February 2016 at 06:23:09 UTC, Daniel Kozak wrote: >> V Fri, 05 Feb 2016 03:47:40 + >> tcak via Digitalmars-d-learn >> napsáno: >> >>> [...] >> >> Did you try

Re: Custom hash table key is const, how to call dtors?

2016-02-05 Thread cy via Digitalmars-d-learn
On Friday, 5 February 2016 at 22:18:50 UTC, Marco Leise wrote: But when you remove items from the table you need to call a const/immutable dtor that needs to be written for everything that can be a hash table key. You need to write destructors for hash keys? How would you use string literals

Re: How do you take the address of a struct in D?

2016-02-05 Thread Enjoys Math via Digitalmars-d-learn
On Friday, 5 February 2016 at 23:53:15 UTC, Enjoys Math wrote: SDL_RenderCopy(...) takes two pointers to SDL_Rect's, I have a property method in another class returning the SDL_Rect equivalent of a Box (my structure). Taking ampersand on the left of a call to the property does not give the

How do you take the address of a struct in D?

2016-02-05 Thread Enjoys Math via Digitalmars-d-learn
SDL_RenderCopy(...) takes two pointers to SDL_Rect's, I have a property method in another class returning the SDL_Rect equivalent of a Box (my structure). Taking ampersand on the left of a call to the property does not give the address (&).

Re: How do you take the address of a struct in D?

2016-02-05 Thread Ali Çehreli via Digitalmars-d-learn
On 02/05/2016 03:53 PM, Enjoys Math wrote: SDL_RenderCopy(...) takes two pointers to SDL_Rect's, I have a property method in another class returning the SDL_Rect equivalent of a Box (my structure). Returning by reference or by value? > Taking ampersand on the left of a call to the property

Re: Custom hash table key is const, how to call dtors?

2016-02-05 Thread Marco Leise via Digitalmars-d-learn
Am Sat, 06 Feb 2016 03:38:54 + schrieb cy : > On Friday, 5 February 2016 at 22:18:50 UTC, Marco Leise wrote: > > But when you remove items from the table you need to call a > > const/immutable dtor that needs to be written for everything > > that can be a hash table

Re: Is this a bug in std.typecons.Tuple.slice?

2016-02-05 Thread tsbockman via Digitalmars-d-learn
On Friday, 5 February 2016 at 19:16:11 UTC, Marco Leise wrote: > 1. Removing 'ref' from the return type Must happen. 'ref' only worked because of the reinterpreting cast which doesn't work in general. This will change the semantics. Now the caller of 'slice' will deal with a whole new copy

"Error: need 'this' for 'bbox' of type 'Bong!(double, 3u)'"

2016-02-05 Thread Enjoys Math via Digitalmars-d-learn
I'm getting that on the last line of this code: auto wh = Vec2([loadSurf.w, loadSurf.h]); wh /= 2; auto x = wh.plus1Dim(pos[Z]); this.bbox = Box3(pos - x, pos + x); Any ideas?

Re: Template to create a type and instantiate it

2016-02-05 Thread cy via Digitalmars-d-learn
On Friday, 5 February 2016 at 07:44:29 UTC, Rikki Cattermole wrote: That code is completely wrong anyway. Well, obviously it's wrong. If I don't know correct code that will do what I want, then I can't tell you what I want using correct code. But you could do: alias Derp = TFoo; Derp

Re: "Error: need 'this' for 'bbox' of type 'Bong!(double, 3u)'"

2016-02-05 Thread Enjoys Math via Digitalmars-d-learn
On Saturday, 6 February 2016 at 04:41:26 UTC, Enjoys Math wrote: I'm getting that on the last line of this code: auto wh = Vec2([loadSurf.w, loadSurf.h]); wh /= 2; auto x = wh.plus1Dim(pos[Z]); this.bbox = Box3(pos - x, pos + x);

Re: Is this a bug in std.typecons.Tuple.slice?

2016-02-05 Thread Saurabh Das via Digitalmars-d-learn
On Friday, 5 February 2016 at 19:16:11 UTC, Marco Leise wrote: Am Fri, 05 Feb 2016 05:31:15 + schrieb Saurabh Das : [...] That is enlightening. I have updated the PR at https://github.com/D-Programming-Language/phobos/pull/3975 to incorporate these changes.

Re: Detecting exception unwinding

2016-02-05 Thread cy via Digitalmars-d-learn
On Friday, 5 February 2016 at 08:16:05 UTC, Ola Fosheim Grøstad wrote: If you can test for "uncaught_exceptions" you can implement the equivalent of scope(failure/success) etc within destructors. Sorry, years of python programming have made me shy of destructors. It just looks a little less