Turn GC allocated string into a scoped heap allocation

2018-12-13 Thread Per Nordlöw via Digitalmars-d-learn
How do I turn the GC-allocation in toLower() to a scoped heap allocation together with toLowerInPlace() in void f(const scope const(char)[] expr) { import std.uni : toLower; loweredExpr = toLower(expr); // temporary // use loweredExpr as key in hash table } when `loweredExpr` is

Re: Can you move a disabled this struct in to a container type if it's an rvalue?

2018-12-13 Thread aliak via Digitalmars-d-learn
On Wednesday, 12 December 2018 at 21:11:38 UTC, Paul Backus wrote: On Wednesday, 12 December 2018 at 20:05:18 UTC, aliak wrote: Ie: struct S { @disable this(); this(int i) {} } struct Container(T) { T value; this(auto ref T value) { this.value = value; } } void

Can you move a disabled this(this) struct in to a container type if it's an rvalue?

2018-12-13 Thread aliak via Digitalmars-d-learn
Ie: struct S { @disable this(this); this(int i) {} } struct Container(T) { T value; this(T value) { this.value = value; } } void main() { auto a = Container!S(S(3)); // can't do this. } I can build a custom constructor for Container that makes this work:

Re: Can you move a disabled this(this) struct in to a container type if it's an rvalue?

2018-12-13 Thread Boris-Barboris via Digitalmars-d-learn
On Thursday, 13 December 2018 at 09:51:42 UTC, aliak wrote: Ie: struct S { @disable this(this); this(int i) {} } struct Container(T) { T value; this(T value) { this.value = value; } } void main() { auto a = Container!S(S(3)); // can't do this. } I can build a

Re: Can you move a disabled this(this) struct in to a container type if it's an rvalue?

2018-12-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/13/18 8:17 AM, aliak wrote: On Thursday, 13 December 2018 at 12:08:22 UTC, Boris-Barboris wrote: On Thursday, 13 December 2018 at 09:51:42 UTC, aliak wrote: [...] You can just move in container constructor: struct S {     @disable this(this);     this(int i) {} } struct

Re: Turn GC allocated string into a scoped heap allocation

2018-12-13 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 13 December 2018 at 13:46:47 UTC, Steven Schveighoffer wrote: If you use loweredExpr as a key in a builtin AA, then you need to make it a heap allocation, because the GC cleans up AAs. -Steve I only need it for lookup not for storage.

Re: Can you move a disabled this(this) struct in to a container type if it's an rvalue?

2018-12-13 Thread aliak via Digitalmars-d-learn
On Thursday, 13 December 2018 at 12:08:22 UTC, Boris-Barboris wrote: On Thursday, 13 December 2018 at 09:51:42 UTC, aliak wrote: [...] You can just move in container constructor: struct S { @disable this(this); this(int i) {} } struct Container(T) { T value; this(T value)

Re: Turn GC allocated string into a scoped heap allocation

2018-12-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/13/18 4:38 AM, Per Nordlöw wrote: How do I turn the GC-allocation in toLower() to a scoped heap allocation together with toLowerInPlace() in void f(const scope const(char)[] expr) {     import std.uni : toLower;     loweredExpr = toLower(expr); // temporary     // use loweredExpr as

Re: Turn GC allocated string into a scoped heap allocation

2018-12-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/13/18 9:06 AM, Per Nordlöw wrote: On Thursday, 13 December 2018 at 13:46:47 UTC, Steven Schveighoffer wrote: If you use loweredExpr as a key in a builtin AA, then you need to make it a heap allocation, because the GC cleans up AAs. I only need it for lookup not for storage. I guess

Re: Bug in shifting

2018-12-13 Thread Daniel Kozak via Digitalmars-d-learn
I do not understand you? What is wrong? It works ok. https://run.dlang.io/is/ZFf0FQ What do you mean by D required breaks for cases? On Fri, Dec 14, 2018 at 1:20 AM Michelle Long via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > byte x = 0xF; > ulong y = x >> 60; > > Does

Re: Print RAM used by arrays

2018-12-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/13/18 4:32 PM, Giovanni Di Maria wrote: Hi. How can I know the amount of RAM allocated by a vector? For example: string[8][1000] array; for(int i=0;i<1000;i++) { array[i]=["","","","","","","",""]; } how can I know the amount of bytes of above matrix?

Print RAM used by arrays

2018-12-13 Thread Giovanni Di Maria via Digitalmars-d-learn
Hi. How can I know the amount of RAM allocated by a vector? For example: string[8][1000] array; for(int i=0;i<1000;i++) { array[i]=["","","","","","","",""]; } how can I know the amount of bytes of above matrix? Can I clean the memory ofter his use, without

Bug in shifting

2018-12-13 Thread Michelle Long via Digitalmars-d-learn
byte x = 0xF; ulong y = x >> 60; Does not compute the proper value. It seems that the shift amount is wrapped. My code is more complex. The code above does give an error. I am using the code in a template. If I change x to ulong it works as expected. I've noticed the compiler is not

Re: Bug in shifting

2018-12-13 Thread Michelle Long via Digitalmars-d-learn
On Friday, 14 December 2018 at 02:17:20 UTC, Jonathan M Davis wrote: On Thursday, December 13, 2018 6:56:33 PM MST Steven Schveighoffer via Digitalmars-d-learn wrote: On 12/13/18 7:16 PM, Michelle Long wrote: > I've noticed the compiler is not throwing up errors and > warnings like it used to:

Re: Bug in shifting

2018-12-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, December 13, 2018 6:56:33 PM MST Steven Schveighoffer via Digitalmars-d-learn wrote: > On 12/13/18 7:16 PM, Michelle Long wrote: > > I've noticed the compiler is not throwing up errors and warnings like it > > used to: > > > > I thought D required breaks for cases? Seems it doesn't

Re: Bug in shifting

2018-12-13 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 14 Dec 2018 00:16:51 +, Michelle Long wrote: > byte x = 0xF; > ulong y = x >> 60; "Error: shift by 60 is outside the range 0..31" This is the result of integer promotion rules. Change the 30 to a 60 and it works, and the result is, as you would expect, 0. > I thought D required

Re: Bug in shifting

2018-12-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/13/18 7:16 PM, Michelle Long wrote: byte x = 0xF; ulong y = x >> 60; Surely you meant x << 60? As x >> 60 is going to be 0, even with a ulong. Does not compute the proper value. It seems that the shift amount is wrapped. My code is more complex. The code above does give an error. I

Re: Can you move a disabled this(this) struct in to a container type if it's an rvalue?

2018-12-13 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 13 December 2018 at 13:17:05 UTC, aliak wrote: Ah. Is there any case where you would not want to do that when you have a T value as parameter? Hypothetically, yes, e.g. an object that contains references to itself. However, D operates on the assumption that you don't have such

Re: Can you move a disabled this(this) struct in to a container type if it's an rvalue?

2018-12-13 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 13 December 2018 at 13:17:05 UTC, aliak wrote: Ah. Is there any case where you would not want to do that when you have a T value as parameter? And, what if it's "this()(auto ref T value)"? Then moving could be dangerous if the parameter was passed as a ref. Or maybe it just