Re: What exactly shared means?

2015-01-02 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 2 January 2015 at 11:47:47 UTC, Daniel Kozak wrote: I always think that shared should be use to make variable global across threads (similar to __gshared) with some synchronize protection. But this code doesn't work (app is stuck on _aaGetX or _aaRehash ): But when I add

std.parallelism.taskPool daemon threads not terminating

2016-06-16 Thread Moritz Maxeiner via Digitalmars-d-learn
So, I am probably overlooking something obvious, but here goes: According to my understanding of daemon threads and what is documented here[1], this following program should terminate once the druntime shuts down, as the thread working on the task is supposed to be a daemon thread: import

Re: std.parallelism.taskPool daemon threads not terminating

2016-06-17 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 17 June 2016 at 14:29:57 UTC, Russel Winder wrote: A priori, assuming I am not missing anything, this behaviour seems entirely reasonable. I agree that when using non-daemon threads (and I personally think that should be the default) that it is. But I cannot bring that into

Re: Force inline

2017-02-20 Thread Moritz Maxeiner via Digitalmars-d-learn
On Monday, 20 February 2017 at 12:47:43 UTC, berni wrote: pragma(inline, true) doesn't work out well: int bar; void main(string[] args) { if (foo()) {} } bool foo() { pragma(inline, true) if (bar==1) return false; if (bar==2) return false; return true; } with dmd -inline

Re: Hello, folks! Newbie to D, have some questions!

2017-02-18 Thread Moritz Maxeiner via Digitalmars-d-learn
On Saturday, 18 February 2017 at 20:15:55 UTC, timmyjose wrote: My rudimentary knowledge of the D ecosystem tells me that there is a GC in D, but that can be turned off. Is this correct? Technically yes; you will lose core functionality, though, if you do. I don't have the complete list at

Re: scope with if

2017-02-18 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 17 February 2017 at 20:06:19 UTC, berni wrote: I wonder if it's possible to do something like this: import std.stdio; void main(string[] args) { if (args[1]=="a") { write("A"); scope (exit) write("B"); } write("C"); } I expected the output to be ACB not

Re: Recommend: IDE and GUI library

2017-02-24 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 24 February 2017 at 22:44:55 UTC, XavierAP wrote: Hi I've looked at wiki.dlang.org/IDEs, and I see that Visual D is linked from dlang.org/download.html. Still I was looking for personal opinions and experiences beyond hard specs, I wonder if one of the IDEs is already dominant at

Re: Calling destroy on struct pointer

2017-02-25 Thread Moritz Maxeiner via Digitalmars-d-learn
On Saturday, 25 February 2017 at 15:21:56 UTC, Radu wrote: The correct way of doing it using deref would to look like: struct A { int i; } auto a = cast (A*) malloc(A.sizeof); // Allocate emplace(a, 42); // Construct destroy(*a); // Destruct A

Re: Calling destroy on struct pointer

2017-02-25 Thread Moritz Maxeiner via Digitalmars-d-learn
On Saturday, 25 February 2017 at 15:13:27 UTC, Radu wrote: Here is sample on how destroy fails with a fwd decl error: struct A { B b; C c; } struct B { Wrap!A val; } struct C { Wrap!A val; } struct Wrap(T) { this(bool b) { t = cast(T*) malloc(T.sizeof);

Re: Calling destroy on struct pointer

2017-02-25 Thread Moritz Maxeiner via Digitalmars-d-learn
On Saturday, 25 February 2017 at 10:44:07 UTC, Radu wrote: On Saturday, 25 February 2017 at 08:36:02 UTC, Ali Çehreli wrote: On 02/25/2017 12:17 AM, Radu wrote: > destroy(cc) -> does c = C.init > destroy(*cc); -> calls the C dtor > > Is this by design? If so - how can I destroy and get the

Re: Calling destroy on struct pointer

2017-02-25 Thread Moritz Maxeiner via Digitalmars-d-learn
On Saturday, 25 February 2017 at 13:14:24 UTC, Moritz Maxeiner wrote: --- struct A {} auto a = cast (A*) malloc(A.sizeof); // Allocate emplace(a, 42); // Construct destroy(a); // Destruct free(a); // Deallocate ---

Re: Recommend: IDE and GUI library

2017-02-25 Thread Moritz Maxeiner via Digitalmars-d-learn
On Saturday, 25 February 2017 at 21:26:32 UTC, XavierAP wrote: It's not GUI projects that I would plan to work on, just something easy with basic functionality that I can use for my own utilities or test clients for libraries. And if there's anything with any kind of designer support (in which

Re: Mallocator and 'shared'

2017-02-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 13:01:44 UTC, Moritz Maxeiner wrote: Of course, I just wanted to point out that Kagamin's post scriptum is a simplification I cannot agree with. As a best practice? Sure. As a "never do it"? No. Sorry for the double post, error in the above, please use this

Re: Mallocator and 'shared'

2017-02-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 10:52:37 UTC, Johannes Pfau wrote: The compiler of course can't require shared methods to be thread-safe as it simply can't prove thread-safety in all cases. This is like shared/trusted: You are supposed to make sure that a function behaves as expected. The

Re: Mallocator and 'shared'

2017-02-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 14:27:05 UTC, Kagamin wrote: On Monday, 13 February 2017 at 17:44:10 UTC, Moritz Maxeiner wrote: To be clear: While I might, in general, agree that using shared methods only for thread safe methods seems to be a sensible restriction, neither language nor

Re: Mallocator and 'shared'

2017-02-12 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 12 February 2017 at 20:08:05 UTC, bitwise wrote: It seems that methods qualified with 'shared' may be what you're suggesting matches up with the 'bridge' I'm trying to describe, but again, using the word 'shared' to mean both 'thread safe' and 'not thread safe' doesn't make sense.

Re: Mallocator and 'shared'

2017-02-12 Thread Moritz Maxeiner via Digitalmars-d-learn
On Monday, 13 February 2017 at 01:30:57 UTC, ag0aep6g wrote: This doesn't make sense to me. b depends on a. If I run thread 1 alone, I can expect b to be 1, no? Thread 2 can then a) read 0, write 1; or b) read 1, write 2. How can b be 0 when the writeln is executed? An example like this

Re: Mallocator and 'shared'

2017-02-13 Thread Moritz Maxeiner via Digitalmars-d-learn
On Monday, 13 February 2017 at 14:20:05 UTC, Kagamin wrote: Thread unsafe methods shouldn't be marked shared, it doesn't make sense. If you don't want to provide thread-safe interface, don't mark methods as shared, so they will not be callable on a shared instance and thus the user will be

Re: how to define my own traits

2017-03-26 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 26 March 2017 at 23:25:49 UTC, XavierAP wrote: I've looked into Phobos to emulate it when defining my own trait template, and when I see this: module std.range.primitives; // ... template isInputRange(R) { enum bool isInputRange = is(typeof( (inout int = 0) { R r

Re: Issue with typeof

2017-03-20 Thread Moritz Maxeiner via Digitalmars-d-learn
On Monday, 20 March 2017 at 17:58:32 UTC, Moritz Maxeiner wrote: 2) Create a template that can be used like this (you'll want to consult std.traits for this): void foo (delegateOf!(T.method) fptr) {} This may sound harder that it is, btw. A template that does exactly that is the following

Re: Deduplicating template reflection code

2017-04-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 14 April 2017 at 08:24:00 UTC, Johannes Pfau wrote: I've got this code duplicated in quite some functions: - [...]1 foreach (MethodType; overloads) { // function dependent code here } [...]2

Re: Deduplicating template reflection code

2017-04-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 14 April 2017 at 11:29:03 UTC, Johannes Pfau wrote: Is there some way to wrap the 'type selection'? In pseudo-code something like this: enum FilteredOverloads(API) = ... foreach(Overload, FilteredOverloads!API) { } Sure, but that's a bit more complex: --- [...] //

Re: Best memory management D idioms

2017-03-08 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 8 March 2017 at 06:42:40 UTC, ag0aep6g wrote: [...] Yes and yes. GCAllocator.allocate calls core.memory.GC.malloc with does pretty much the same thing as the builtin `new`. Nitpicking: `new` is typed (i.e. allocation+construction), `malloc` and `allocate` are not (only

Re: Deduplicating template reflection code

2017-04-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 14 April 2017 at 17:57:49 UTC, Johannes Pfau wrote: Am Fri, 14 Apr 2017 13:41:45 + schrieb Moritz Maxeiner : [...] Great, thanks that's exactly the solution I wanted. Figuring this out by myself is a bit above my template skill level ;-) -- Johannes

Re: Problem with dtor behavior

2017-07-28 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 28 July 2017 at 11:39:56 UTC, SrMordred wrote: On Thursday, 27 July 2017 at 20:28:47 UTC, Moritz Maxeiner wrote: On Thursday, 27 July 2017 at 19:19:27 UTC, SrMordred wrote: //D-CODE struct MyStruct{ int id; this(int id){ writeln("ctor"); } ~this(){

Re: GC

2017-07-30 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 30 July 2017 at 09:12:53 UTC, piotrekg2 wrote: I would like to learn more about GC in D. [...] It would be great if you could point me out to articles on this subject. The primary locations to get information are the language specification [1] and the druntime documentation [2]. I

Re: Adding deprecated to an enum member

2017-08-01 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 1 August 2017 at 01:12:28 UTC, Jeremy DeHaan wrote: I got an error today because I added deprecated to an enum member. Is there a way to achieve this, or am I out of luck? If it isn't doable, should it be? Here's what I want: [...] It's a bug [1]. [1]

Re: this r-value optimizations

2017-08-01 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 1 August 2017 at 22:47:24 UTC, Nordlöw wrote: Given the `struct S` with lots of data fields, I've written the following functional way of initializing only a subset of the members in an instance of `S`: struct S { [...] } Now the question becomes: will the S-copying inside

Re: WTF is going on! Corrupt value that is never assigned

2017-07-13 Thread Moritz Maxeiner via Digitalmars-d-learn
On Thursday, 13 July 2017 at 18:22:34 UTC, FoxyBrown wrote: The following code is pretty screwed up, even though it doesn't look like it. I have a buf, a simple malloc which hold the results of a win32 call. I am then trying to copy over the data in buf to a D struct. But when copying the

Re: Read from terminal when enter is pressed, but do other stuff in the mean time...

2017-07-13 Thread Moritz Maxeiner via Digitalmars-d-learn
On Thursday, 13 July 2017 at 15:52:57 UTC, Dustmight wrote: How do I read in input from the terminal without sitting there waiting for it? I've got code I want to run while there's no input, and then code I want to act on input when it comes in. How do I do both these things? As Stefan

Re: WTF is going on! Corrupt value that is never assigned

2017-07-13 Thread Moritz Maxeiner via Digitalmars-d-learn
On Thursday, 13 July 2017 at 22:53:45 UTC, FoxyBrown wrote: On Thursday, 13 July 2017 at 20:35:19 UTC, Moritz Maxeiner wrote: On Thursday, 13 July 2017 at 18:22:34 UTC, FoxyBrown wrote: The following code is pretty screwed up, even though it doesn't look like it. I have a buf, a simple malloc

Re: Application settings

2017-07-07 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 7 July 2017 at 19:40:35 UTC, FoxyBrown wrote: What's the "best" way to do this? I want something I can simply load at startup in a convenient and easy way then save when necessary(possibly be efficient at it, but probably doesn't matter). Simply json an array and save and load it,

Re: "shared" woes: shared instances of anonymous classes

2017-07-07 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 7 July 2017 at 09:14:56 UTC, Arafel wrote: [...] Is there any way to create a shared instance of an anonymous class? [...] If somebody knows how this works / is supposed to work, I'd be thankful! [1]: https://dpaste.dzfl.pl/ce2ba93111a0 Yes, but it's round about: you have to

Re: Why do array literals default to object.Object[]?

2017-07-13 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 05:24:49 UTC, Brandon Buck wrote: On Wednesday, 12 July 2017 at 02:06:41 UTC, Steven Schveighoffer wrote: I'm sure there's a bug filed somewhere on this... Is this bug worthy? I can search for one and comment and/or create one if I can't find one. It's at

Re: Bad file descriptor in File destructor

2017-07-13 Thread Moritz Maxeiner via Digitalmars-d-learn
On Thursday, 13 July 2017 at 08:38:52 UTC, unDEFER wrote: Hello! I have the code like this: File file; try { file = File(path); } catch (Exception exp) { return; } ... try { } Where does that `File` come from? If it's std.stdio.File, that one

Re: Bad file descriptor in File destructor

2017-07-13 Thread Moritz Maxeiner via Digitalmars-d-learn
On Thursday, 13 July 2017 at 10:56:20 UTC, unDEFER wrote: Seems I have found. I must do: try{ File file; try { file = File(path); } catch (Exception exp) { return; } //Some actions with file } catch (ErrnoException) { return; } Well, yes, you

Re: Bad file descriptor in File destructor

2017-07-13 Thread Moritz Maxeiner via Digitalmars-d-learn
On Thursday, 13 July 2017 at 11:15:56 UTC, Moritz Maxeiner wrote: --- ubyte[File.sizeof] _file; ref File file() { return *(cast(File*) &_file[0]); } [create File instance and assign to file] scope (exit) destroy(file); --- Forgot to add the try catch: --- ubyte[File.sizeof] _file; ref File

Re: Bad file descriptor in File destructor

2017-07-13 Thread Moritz Maxeiner via Digitalmars-d-learn
On Thursday, 13 July 2017 at 10:28:30 UTC, unDEFER wrote: On Thursday, 13 July 2017 at 08:53:24 UTC, Moritz Maxeiner wrote: Where does that `File` come from? If it's std.stdio.File, that one is a struct with internal reference counting, so it shouldn't crash in the above. Could you provide a

Re: How to get value of type at CT given only an alias

2017-07-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 14 July 2017 at 18:06:49 UTC, Steven Schveighoffer wrote: .init is the default value. I'm not sure you can get the default value of a non-default initializer, My attempts using init didn't work. e.g.: void foo(alias T)() { pragma(msg, T.init); } struct S { int y = 5;

Re: Exception handling

2017-07-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 14 July 2017 at 20:22:21 UTC, Ali Çehreli wrote: On 07/14/2017 12:36 PM, ANtlord wrote: > Hello! I've tried to use nothrow keyword and I couldn't get a state of > function satisfied the keyword. I have one more method that can throw an > exception; it is called inside nothrow method.

Re: Exception handling

2017-07-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 14 July 2017 at 21:20:29 UTC, Jonathan M Davis wrote: On Friday, July 14, 2017 9:06:52 PM MDT Moritz Maxeiner via Digitalmars-d- learn wrote: On Friday, 14 July 2017 at 20:22:21 UTC, Ali Çehreli wrote: > Although it's obvious to us that there are only those two > exce

Re: Exception handling

2017-07-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 14 July 2017 at 23:09:23 UTC, Stefan Koch wrote: On Friday, 14 July 2017 at 23:02:24 UTC, Moritz Maxeiner wrote: On Friday, 14 July 2017 at 21:20:29 UTC, Jonathan M Davis wrote: Basically, the compiler _never_ looks at the bodies of other functions when determining which attributes

Re: WTF is going on! Corrupt value that is never assigned

2017-07-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Thursday, 13 July 2017 at 23:30:39 UTC, Moritz Maxeiner wrote: Okay, I'll setup a Windows VM when I have time and check it out (unless someone solves it beforehand). I have been unable to reproduce your reported behaviour with dmd 2.074.1 (same as Adam).

Re: Adding flags to dub build

2017-07-18 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 18 July 2017 at 20:12:13 UTC, Jean-Louis Leroy wrote: On Tuesday, 18 July 2017 at 20:00:48 UTC, Guillaume Piolat wrote: On Tuesday, 18 July 2017 at 19:49:35 UTC, Jean-Louis Leroy wrote: Hi, I want to add a few flags while building with dub. I tried:

Re: Creating a new type, to get strong-ish type checking and restrict usage to certain operations, using struct perhaps

2017-07-21 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 21 July 2017 at 18:49:21 UTC, Cecil Ward wrote: I was think about how to create a new type that holds packed bcd values, of a choice of widths, that must fit into a uint32_t or a uint64_t (not really long multi-byte objects). I am not at all sure how to do it. I thought about using

Re: Creating a new type, to get strong-ish type checking and restrict usage to certain operations, using struct perhaps

2017-07-22 Thread Moritz Maxeiner via Digitalmars-d-learn
On Saturday, 22 July 2017 at 03:18:29 UTC, Cecil Ward wrote: I guess part of my question, which I didn't really highlight well enough, is the issue of strong typing. [...] Going back to the original example of packed bcd stored in a uint64_t say, first thing is that I want to ban illegal

Re: Creating a new type, to get strong-ish type checking and restrict usage to certain operations, using struct perhaps

2017-07-22 Thread Moritz Maxeiner via Digitalmars-d-learn
On Saturday, 22 July 2017 at 06:08:59 UTC, Cecil Ward wrote: On Saturday, 22 July 2017 at 03:18:29 UTC, Cecil Ward wrote: [...] I saw David Nadlinger's units package. I'd like to know how the strong typing works. By wrapping in structs and overloading operators [1][2][3][4]. [1]

Re: Prevent destroy() from calling base deconstructor of a derived class?

2017-07-25 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 25 July 2017 at 17:50:18 UTC, Dragonson wrote: I need to call only the deconstructor of the derived class I have an instance of, not every deconstructor in the inheritance chain. Putting `override` before the destructor doesn't compile so I'm not sure how to achieve this? Call

Re: Problem with dtor behavior

2017-07-27 Thread Moritz Maxeiner via Digitalmars-d-learn
On Thursday, 27 July 2017 at 19:19:27 UTC, SrMordred wrote: //D-CODE struct MyStruct{ int id; this(int id){ writeln("ctor"); } ~this(){ writeln("dtor"); } } MyStruct* obj; void push(T)(auto ref T value){ obj[0] = value; } void main() { obj =

Re: Bulk allocation and partial deallocation for tree data structures.

2017-07-03 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 4 July 2017 at 03:13:14 UTC, Filip Bystricky wrote: Oh and I forgot to mention: another use-case for this would be for arrays. For manually managed arrays like std.container.array, it would make it possible to transfer ownership of individual objects from the array back to the

Re: Bulk allocation and partial deallocation for tree data structures.

2017-07-03 Thread Moritz Maxeiner via Digitalmars-d-learn
On Monday, 3 July 2017 at 17:06:10 UTC, Ali Çehreli wrote: On 07/02/2017 07:56 PM, Stefan Koch wrote: On Monday, 3 July 2017 at 02:51:49 UTC, Filip Bystricky wrote: Anyone? The answer is no. Partial deallocation in an arbitrary fashion is not advisable. And there are no standard library

Re: Bulk allocation and partial deallocation for tree data structures.

2017-07-03 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 4 July 2017 at 02:53:00 UTC, Filip Bystricky wrote: On Tuesday, 4 July 2017 at 01:56:11 UTC, Moritz Maxeiner wrote: [...] However, in many cases it is unacceptable to have to prevent the whole block from being freed (especially if the memory is managed by a compacting gc).

Re: Advice wanted on garbage collection of sockets for c++ programmer using D

2017-06-28 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 28 June 2017 at 09:16:22 UTC, Guillaume Piolat wrote: So far everyone is ignoring my example when A needs B to be destroyed. This happens as soon as you use DerelictUtil for example. I thought I had (implicitly): B needs to be `@disable finalize`.

Re: Advice wanted on garbage collection of sockets for c++ programmer using D

2017-06-28 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 28 June 2017 at 09:22:07 UTC, Guillaume Piolat wrote: Deterministic destruction is a _solved_ problem in C++, and a number of users to convert are now coming from C++. It is also in D, as long as you don't use the GC (which is inherently non-deterministic). 3. Suggest a

Re: Advice wanted on garbage collection of sockets for c++ programmer using D

2017-06-28 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 28 June 2017 at 12:33:24 UTC, Guillaume Piolat wrote: On Wednesday, 28 June 2017 at 11:34:17 UTC, Moritz Maxeiner wrote: Requirement: Do not allocate using the GC Option 1) Use structs with `@disable this`, `@disable this(this)`, and a destructor that checks whether the resource

Re: Advice wanted on garbage collection of sockets for c++ programmer using D

2017-06-28 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 28 June 2017 at 12:28:28 UTC, Guillaume Piolat wrote: On Wednesday, 28 June 2017 at 11:21:07 UTC, Moritz Maxeiner wrote: On Wednesday, 28 June 2017 at 09:16:22 UTC, Guillaume Piolat wrote: So far everyone is ignoring my example when A needs B to be destroyed. This happens as soon

Re: Advice wanted on garbage collection of sockets for c++ programmer using D

2017-06-27 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 27 June 2017 at 23:42:38 UTC, Guillaume Piolat wrote: On Tuesday, 27 June 2017 at 18:04:36 UTC, Moritz Maxeiner wrote: Well, technically speaking the `~this` for D classes *is* a finalizer that you may optionally manually call (e.g. via destroy). It would be nice, though, to

Re: Advice wanted on garbage collection of sockets for c++ programmer using D

2017-06-27 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 28 June 2017 at 02:13:10 UTC, Jonathan M Davis wrote: On Wednesday, June 28, 2017 01:11:35 Moritz Maxeiner via Digitalmars-d-learn wrote: Not every class can't be finalized, so it might make sense for finalization to remain an available option. There are definitely cases where

Re: Create class on stack

2017-08-05 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 6 August 2017 at 01:18:50 UTC, Johnson Jones wrote: On Saturday, 5 August 2017 at 23:09:09 UTC, Moritz Maxeiner wrote: On Saturday, 5 August 2017 at 17:08:32 UTC, Johnson Jones wrote: using gtk, it has a type called value. One has to use it to get the value of stuff but it is a

Re: Create class on stack

2017-08-05 Thread Moritz Maxeiner via Digitalmars-d-learn
On Saturday, 5 August 2017 at 17:08:32 UTC, Johnson Jones wrote: using gtk, it has a type called value. One has to use it to get the value of stuff but it is a class. Once it is used, one doesn't need it. Ideally I'd like to treat it as a struct since I'm using it in a delegate I would like

Re: Create class on stack

2017-08-06 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 6 August 2017 at 02:19:19 UTC, FoxyBrown wrote: [...] I don't think you understand what I'm saying. If I use this method to create a "reference" type on the stack rather than the heap, is the only issue worrying about not having that variable be used outside that scope(i.e., have

Re: D move semantics

2017-07-30 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 30 July 2017 at 16:12:41 UTC, piotrekg2 wrote: What is the idiomatic D code equivalent to this c++ code? There's no direct equivalent of all your code to D using only druntime+phobos AFAIK. class Block { [...] }; Since you don't seem to be using reference type semantics or

Re: Struct Postblit Void Initialization

2017-07-30 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 30 July 2017 at 19:22:07 UTC, Jiyan wrote: Hey, just wanted to know whether something like this would be possible sowmehow: struct S { int m; int n; this(this) { m = void; n = n; } } So not the whole struct is moved everytime f.e. a function is called, but only n has to be

Re: Create class on stack

2017-08-08 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 8 August 2017 at 05:37:41 UTC, ANtlord wrote: On Sunday, 6 August 2017 at 15:47:43 UTC, Moritz Maxeiner wrote: If you use this option, do be aware that this feature has been > scheduled for future deprecation [1]. It's likely going to continue working for quite a while (years),

Re: Specify dmd or ldc compiler and version in a json dub file?

2017-08-08 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 8 August 2017 at 09:17:02 UTC, data pulverizer wrote: Hi, I would like to know how to specify dmd or ldc compiler and version in a json dub file. Thanks in advance. You can't [1]. You can specify the compiler to use only on the dub command line via `--compiler=`. [1]

Re: Specify dmd or ldc compiler and version in a json dub file?

2017-08-08 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 8 August 2017 at 09:31:49 UTC, data pulverizer wrote: On Tuesday, 8 August 2017 at 09:21:54 UTC, Moritz Maxeiner wrote: On Tuesday, 8 August 2017 at 09:17:02 UTC, data pulverizer wrote: Hi, I would like to know how to specify dmd or ldc compiler and version in a json dub file.

Re: Get Dll functions at compile time

2017-08-09 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 9 August 2017 at 02:11:13 UTC, Johnson Jones wrote: I like to create code that automates much of the manual labor that we, as programmers, are generally forced to do. D generally makes much of this work automatable. For example, I have created the following code which makes

Re: if (auto x = cast(C) x)

2017-08-09 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 9 August 2017 at 21:54:46 UTC, Q. Schroll wrote: For a class/interface type `A` and a class `C` inheriting from `A` one can do A a = getA(); if (auto c = cast(C) a) { .. use c .. } to get a `C` view on `a` if it happens to be a `C`-instance. Sometimes one cannot find a

Re: gtk interface responsiveness

2017-08-07 Thread Moritz Maxeiner via Digitalmars-d-learn
On Monday, 7 August 2017 at 22:02:21 UTC, Johnson Jones wrote: I have an icon that I toggle which clicked. It seems that I can't toggle it any faster than about a second. The handler is being called each click but it seems the gui is not updated more than about 1fps in that case? Although,

Re: Create class on stack

2017-08-07 Thread Moritz Maxeiner via Digitalmars-d-learn
On Monday, 7 August 2017 at 22:02:07 UTC, Mike wrote: On Monday, 7 August 2017 at 13:42:33 UTC, Moritz Maxeiner wrote: You can still create a (scope) class on the stack, escape a reference to it using `move` and use it afterwards, all within the rules of @safe, so I'm not convinced that the

Re: x64 build time 3x slower?

2017-08-07 Thread Moritz Maxeiner via Digitalmars-d-learn
On Monday, 7 August 2017 at 22:19:57 UTC, Johnson Jones wrote: Why would that be. Program take about 4 seconds to compile and 12 for x64. There is fundamentally no difference between the two versions. I do link in gtk x86 and gtk x64 depending on version, and that's it as far as I can tell.

Re: Create class on stack

2017-08-07 Thread Moritz Maxeiner via Digitalmars-d-learn
On Monday, 7 August 2017 at 10:42:03 UTC, Jacob Carlborg wrote: On 2017-08-06 17:47, Moritz Maxeiner wrote: If you use this option, do be aware that this feature has been scheduled for future deprecation [1]. It's likely going to continue working for quite a while (years), though. It's

Re: Create class on stack

2017-08-07 Thread Moritz Maxeiner via Digitalmars-d-learn
On Monday, 7 August 2017 at 13:40:18 UTC, Moritz Maxeiner wrote: Thanks, I wasn't aware of this. I tried fooling around scope classes and DIP1000 for a bit and was surprised that this is allowed: --- import core.stdc.stdio : printf; import std.algorithm : move; class A { int i;

Re: Create class on stack

2017-08-07 Thread Moritz Maxeiner via Digitalmars-d-learn
On Monday, 7 August 2017 at 10:50:21 UTC, Mike wrote: On Sunday, 6 August 2017 at 15:47:43 UTC, Moritz Maxeiner wrote: If you use this option, do be aware that this feature has been scheduled for future deprecation [1]. It's likely going to continue working for quite a while (years), though.

Re: Create class on stack

2017-08-06 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 6 August 2017 at 15:24:55 UTC, Jacob Carlborg wrote: On 2017-08-05 19:08, Johnson Jones wrote: using gtk, it has a type called value. One has to use it to get the value of stuff but it is a class. Once it is used, one doesn't need it. Ideally I'd like to treat it as a struct since

Re: Different Output after each execution

2017-08-18 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 18 August 2017 at 15:46:13 UTC, Vino.B wrote: On Friday, 18 August 2017 at 11:24:24 UTC, Moritz Maxeiner wrote: On Friday, 18 August 2017 at 10:50:28 UTC, Moritz Maxeiner wrote: On Friday, 18 August 2017 at 10:06:04 UTC, Vino wrote: On Friday, 18 August 2017 at 08:34:39 UTC, ikod

Re: Parameter File reading

2017-08-23 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 23 August 2017 at 10:25:48 UTC, Vino.B wrote: Hi All, Can anyone provide me a example code on how to read a parameter file and use those parameter in the program. From, Vino.B For small tools I use JSON files via asdf[1]. As an example you can look at the tunneled settings

Re: ore.exception.RangeError

2017-08-23 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 23 August 2017 at 05:53:46 UTC, ag0aep6g wrote: On 08/23/2017 07:45 AM, Vino.B wrote: Execution : rdmd Summary.d - Not working rdmd Summary.d test - Working Program: void main (string[] args) { if(args.length != 2 ) writefln("Unknown operation: %s", args[1]); } When

Re: Long File path Exception:The system cannot find the path specified

2017-08-23 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 23 August 2017 at 05:06:50 UTC, Vino.B wrote: Hi All, When i run the below code in windows i am getting "The system cannot find the path specified" even though the path exist , the length of the path is 516 as below, request your help. Path :

Re: Long File path Exception:The system cannot find the path specified

2017-08-23 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 23 August 2017 at 12:01:20 UTC, Vino.B wrote: On Wednesday, 23 August 2017 at 11:29:07 UTC, Moritz Maxeiner wrote: On which line do you get the Exception? Does it happen with shorter paths, as well? Assuming it happens with all paths: Just to be sure, is each of those

Re: Long File path Exception:The system cannot find the path specified

2017-08-23 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 23 August 2017 at 13:04:28 UTC, Vino.B wrote: The line it complains is std.file.FileException@std\file.d(3713):even after enabling debug it points to the same Output: D:\DScript>rdmd -debug Test.d -r dryrun std.file.FileException@std\file.d(3713):

Re: Different Output after each execution

2017-08-18 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 18 August 2017 at 10:06:04 UTC, Vino wrote: On Friday, 18 August 2017 at 08:34:39 UTC, ikod wrote: On Friday, 18 August 2017 at 08:00:26 UTC, Vino.B wrote: Hi All, I have written a small program to just list the directories, but when i run the program each time i am getting

Re: Different Output after each execution

2017-08-18 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 18 August 2017 at 10:50:28 UTC, Moritz Maxeiner wrote: On Friday, 18 August 2017 at 10:06:04 UTC, Vino wrote: On Friday, 18 August 2017 at 08:34:39 UTC, ikod wrote: On Friday, 18 August 2017 at 08:00:26 UTC, Vino.B wrote: Hi All, I have written a small program to just list the

Re: What is Base64 part in Base64.encode

2017-05-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 14 May 2017 at 21:34:35 UTC, zabruk70 wrote: On Sunday, 14 May 2017 at 21:22:20 UTC, Moritz Maxeiner wrote: The full line is `alias Base64 = Base64Impl!('+', '/');` Yes. When we use it like this: const(char)[] encoded = Base64.encode(data); then template instantiated and

Re: avoid extra variable during void pointer cast

2017-05-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 14 May 2017 at 21:16:04 UTC, Stanislav Blinov wrote: On the point of "not possible...", "only a symbol...", etc: T* ptrCast(T, alias ptr)() { return cast(T*)ptr; } void addInt(void* state, void* data) { alias _state = ptrCast!(int, state); alias _data = ptrCast!(int, data);

Re: What is Base64 part in Base64.encode

2017-05-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 14 May 2017 at 20:04:07 UTC, zabruk70 wrote: I look to std.base64 module source. And dont unerstand what is the "Base64" part in "Base64.encode(data)" example. I see std.base64 module use template Base64Impl. I see alias Base64 = Base64Impl!... But down understand. Base64 not

Re: avoid extra variable during void pointer cast

2017-05-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 14 May 2017 at 22:00:58 UTC, Stanislav Blinov wrote: [...] Yep, it's an alias to template function instantiation, that is, concrete function - a symbol. Yes, my bad :( But of course, it *is* going to be called on every "dereference". GDC optimizes the call away starting at

Re: avoid extra variable during void pointer cast

2017-05-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 14 May 2017 at 21:55:01 UTC, ag0aep6g wrote: On 05/14/2017 11:35 PM, Moritz Maxeiner wrote: On Sunday, 14 May 2017 at 21:16:04 UTC, Stanislav Blinov wrote: [...] T* ptrCast(T, alias ptr)() { return cast(T*)ptr; } [...] alias _state = ptrCast!(int, state); [...] That's a

Re: avoid extra variable during void pointer cast

2017-05-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 14 May 2017 at 20:18:24 UTC, Kevin Brogan wrote: I have a piece of code that takes a callback function. The callback has the signature void callback(void* state, void* data) There are several of these functions. All of them use state and data as differing types. As an example,

Re: Looking for an equivalent to C++ std::getline in D

2017-05-09 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 9 May 2017 at 19:11:08 UTC, Jonathan M Davis wrote: LOL. I get the impression that it's often the tendancy of D folks is to get excited when D shows up as high in a list like Tiobe and to argue that the list doesn't mean much if D isn't high in the list. AKA confirmation bias.

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-10 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 10 May 2017 at 21:19:21 UTC, Stanislav Blinov wrote: "nothrow" does not turn off exceptions, it simply forbids throwing them in the enclosing scope (i.e. calling anything that might throw is not allowed). nothrow disallows the function scope to throw exceptions not derived from

Re: libc dependency

2017-06-19 Thread Moritz Maxeiner via Digitalmars-d-learn
On Monday, 19 June 2017 at 23:29:46 UTC, Steven Schveighoffer wrote: I don't know what's involved in creating those wrappers, but I can't imagine it's difficult to do with D (it's probably actually easier than in C/assembly). Not difficult, but a tedious amount of work for no inherent

Re: libc dependency

2017-06-20 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 20 June 2017 at 11:00:00 UTC, Nemanja Boric wrote: On Monday, 19 June 2017 at 21:45:56 UTC, Moritz Maxeiner wrote: On Monday, 19 June 2017 at 21:35:56 UTC, Steven Schveighoffer wrote: IIRC, Tango did not depend on libc at all. It only used system calls. So it certainly is possible.

Re: libc dependency

2017-06-20 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 20 June 2017 at 11:26:44 UTC, Jacob Carlborg wrote: Yes. But it would be nice to not be dependent on glibc. If we could use musl it would be a lot easier to create our own tool chain (and get full support for static liking). Yes, please. Avoiding the need to download the C tool

Re: libc dependency

2017-06-20 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 20 June 2017 at 12:09:06 UTC, Jacob Carlborg wrote: LLD, the LLVM linker [1]. As far as I understand it, it also support cross-platform linking. Using LDC, musl and LLD you have a fully working cross-compiler tool chain. You might need some extra libraries as well, depending on

Re: casting to structure

2017-06-24 Thread Moritz Maxeiner via Digitalmars-d-learn
On Saturday, 24 June 2017 at 20:43:48 UTC, Igor Shirkalin wrote: I'm in trouble with opCast function. Is it possible to cast some (integral) type to user defined structure? Hi, unfortunately not: - Operator overloading is supported via member functions only [1]. - Corollary: You cannot

Re: casting to structure

2017-06-24 Thread Moritz Maxeiner via Digitalmars-d-learn
On Saturday, 24 June 2017 at 21:11:13 UTC, Igor Shirkalin wrote: Is it possible without such a constructor? No. Also, the above works because of the following [1]: Casting a value v to a struct S, when value is not a struct of the same type, is equivalent to: `S(v)` [1]

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 25 June 2017 at 15:58:48 UTC, Johan Engelen wrote: [...] If version(X) is not defined, there should be no call and no extra code at -O0. [...] In C, you could do something like: ``` #if X void foo() {..} #else #define foo() #endif ``` How would you do this in D? By

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 25 June 2017 at 21:55:22 UTC, Johan Engelen wrote: On Sunday, 25 June 2017 at 16:31:52 UTC, Moritz Maxeiner wrote: By requiring the compiler to inline the empty foo: This won't work. Yes, it does; comment out the call to `foo` and notice no change in the assembly in my link.

Re: Search for, o/w create element for AA

2017-06-19 Thread Moritz Maxeiner via Digitalmars-d-learn
On Monday, 19 June 2017 at 15:19:19 UTC, Q. Schroll wrote: I have to lookup x twice and it seems that there is no way around it. Can't I tell the AA to set a value for a given key if it doesn't already have one (1) with only one lookup, and (2) in a safe way? AFAIK the builtin associate

  1   2   >