Re: Real beginner traits question

2017-09-24 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 25, 2017 at 05:28:13AM +, WhatMeForget via Digitalmars-d-learn wrote: > > This is taken exactly from the traits documentation. > > > > 25 Traits > > 25.21 identifier > > Takes one argument, a symbol. Returns the identifier for t

Re: Real beginner traits question

2017-09-24 Thread rikki cattermole via Digitalmars-d-learn
On 25/09/2017 6:28 AM, WhatMeForget wrote: This is taken exactly from the traits documentation. 25 Traits 25.21 identifier Takes one argument, a symbol. Returns the identifier for that symbol as a string literal. ---

Real beginner traits question

2017-09-24 Thread WhatMeForget via Digitalmars-d-learn
This is taken exactly from the traits documentation. 25 Traits 25.21 identifier Takes one argument, a symbol. Returns the identifier for that symbol as a string literal. There are no example

Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread Haridas via Digitalmars-d-learn
In your case, the postblit of Bar is still going to run and add a ref to it's count when you place it in Foo, right? That means that if you don't destroy it, it will leak memory or resources. Actually no. Since when Foo (class that instantiates Bar) gets GCed, that is the point that I need t

Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread bitwise via Digitalmars-d-learn
On Monday, 25 September 2017 at 01:46:15 UTC, Haridas wrote: [...] It all works well so far. But as soon as I create an instance of Bar inside a Dlang class (say Foo) or as part of a Dlang dynamic array, hell follows. At some point, Dlang's GC kicks in and Bar's destructor gets called from wi

Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread Haridas via Digitalmars-d-learn
In general, of course, this is a bad idea - there's probably a reason that destructor does the thing it's doing. If you're sure skipping it is what you want, go ahead. @Biotronic, the code you have provided may be exactly what I am looking for. Let me explain my situation. I have a library t

Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread bitwise via Digitalmars-d-learn
On Sunday, 24 September 2017 at 17:11:26 UTC, Haridas wrote: In the following code, Bar is an element of struct Foo. Is there a way to avoid a call to ~Bar when ~Foo is getting executed? Don't construct it to begin with. struct Bar { import std.stdio : writeln; int a = 123; void

Re: Struct List Human

2017-09-24 Thread dark777 via Digitalmars-d-learn
On Sunday, 24 September 2017 at 18:00:32 UTC, Adam D. Ruppe wrote: I think readf("%s") reads everything available. readf(" %s\n") might help but personally, I say avoid readf. Just use readln and to!int instead auto line = readln(); if(line.length == 0) writeln("please enter a number"); a

Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread Biotronic via Digitalmars-d-learn
On Sunday, 24 September 2017 at 18:46:15 UTC, Haridas wrote: Also consider the following code. Please let me know if I am doing the right thing for dynamic arrays. My hack seems to have the desired effect on shutting down the destructor. Is this hack legal use of D? Can you please guide me if/h

Re: Struct List Human

2017-09-24 Thread dark777 via Digitalmars-d-learn
On Sunday, 24 September 2017 at 17:05:11 UTC, Neia Neutuladh wrote: On Sunday, 24 September 2017 at 16:13:30 UTC, dark777 wrote: when you execute and call Name: I type my name: Name: dark777 + [enter] and he does not jump to the next line to get the age This is what I want to know how to solve

Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread Haridas via Digitalmars-d-learn
Also consider the following code. Please let me know if I am doing the right thing for dynamic arrays. My hack seems to have the desired effect on shutting down the destructor. Is this hack legal use of D? Can you please guide me if/how it can be achieved for std.container.Array? // impo

Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread Haridas via Digitalmars-d-learn
Thanks Adam Actually Bar's API and implementation is not in my control. Consider the scenario where it is implemented in a library. Or a scenario where I have millions of instances of Bar (not necessarily as a component of Foo) and I do not want to add to runtime memory footprint. Ok, consi

Re: Struct List Human

2017-09-24 Thread Adam D. Ruppe via Digitalmars-d-learn
I think readf("%s") reads everything available. readf(" %s\n") might help but personally, I say avoid readf. Just use readln and to!int instead auto line = readln(); if(line.length == 0) writeln("please enter a number"); age = to!int(line); to is from import std.conv

Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 24 September 2017 at 17:11:26 UTC, Haridas wrote: In the following code, Bar is an element of struct Foo. Is there a way to avoid a call to ~Bar when ~Foo is getting executed? No, but you could just set a flag in Bar that the destructor checks and skips running if it is set. In f

Is it possible to avoid call to destructor for structs?

2017-09-24 Thread Haridas via Digitalmars-d-learn
In the following code, Bar is an element of struct Foo. Is there a way to avoid a call to ~Bar when ~Foo is getting executed? // >> import std.stdio; struct Foo { Bar bar; ~this() { writeln("~Foo"); // some code that disables call to ~Bar } } struct Bar { ~this() {

Re: Struct List Human

2017-09-24 Thread Neia Neutuladh via Digitalmars-d-learn
On Sunday, 24 September 2017 at 16:13:30 UTC, dark777 wrote: when you execute and call Name: I type my name: Name: dark777 + [enter] and he does not jump to the next line to get the age This is what I want to know how to solve. Add a `writeln();` after reading input, maybe?

Re: Struct List Human

2017-09-24 Thread dark777 via Digitalmars-d-learn
On Sunday, 24 September 2017 at 15:51:01 UTC, dark777 wrote: On Sunday, 24 September 2017 at 15:22:30 UTC, Suliman wrote: On Sunday, 24 September 2017 at 14:32:14 UTC, dark777 wrote: I have the following code: https://pastebin.com/PWuaXJNp but typing my name does not go to the next line as soon

Re: Struct List Human

2017-09-24 Thread dark777 via Digitalmars-d-learn
On Sunday, 24 September 2017 at 15:22:30 UTC, Suliman wrote: On Sunday, 24 September 2017 at 14:32:14 UTC, dark777 wrote: I have the following code: https://pastebin.com/PWuaXJNp but typing my name does not go to the next line as soon as I press enter how to solve this? use writeln instead w

Re: Struct List Human

2017-09-24 Thread Suliman via Digitalmars-d-learn
On Sunday, 24 September 2017 at 14:32:14 UTC, dark777 wrote: I have the following code: https://pastebin.com/PWuaXJNp but typing my name does not go to the next line as soon as I press enter how to solve this? use writeln instead write

Struct List Human

2017-09-24 Thread dark777 via Digitalmars-d-learn
I have the following code: https://pastebin.com/PWuaXJNp but typing my name does not go to the next line as soon as I press enter how to solve this?