Re: variable _param_0 cannot be read at compile time

2018-08-08 Thread learnfirst1 via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 13:13:42 UTC, Simen Kjærås wrote: On Wednesday, 8 August 2018 at 12:57:43 UTC, learnfirst1 wrote: Why this is a error ? ``` struct S { bool v; string x; } S* add(A...)(ref A a) { __gshared s = S(a); return } void main(){

Re: How do you put log calls in constructors when they may be created in a static context?

2018-08-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, August 8, 2018 3:54:34 PM MDT aliak via Digitalmars-d-learn wrote: > I'm trying to debug stuff, so I want to add verbose logging > > struct S(T) { >this() { > writeln("created S(T) with properties and ID"); >} > } > > static a = S!int(); // bah > > I guess users can

How do you put log calls in constructors when they may be created in a static context?

2018-08-08 Thread aliak via Digitalmars-d-learn
I'm trying to debug stuff, so I want to add verbose logging struct S(T) { this() { writeln("created S(T) with properties and ID"); } } static a = S!int(); // bah I guess users can call this code from any context, but when i'd also like to see the log output for debugging purposes. Is

Re: float/double to string (pure nothrow @nogc)

2018-08-08 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 17:08:57 UTC, vit wrote: Hello, is in phobos some function which convert float/double to string and is pure @nogc and nothrow? Short answer: no. Long answer: https://issues.dlang.org/show_bug.cgi?id=17628

Re: float/double to string (pure nothrow @nogc)

2018-08-08 Thread ketmar via Digitalmars-d-learn
vit wrote: thanks, that code can be modified to pure nothrow @nogc @safe. Is that lib ok? Is little complicated... converting float to string is a *very* complicated task. that lib is quite small for what it is doing ('cause it hacks around some... interesting cases). the *real* thing will

Re: float/double to string (pure nothrow @nogc)

2018-08-08 Thread vit via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 17:40:11 UTC, ketmar wrote: vit wrote: Hello, is in phobos some function which convert float/double to string and is pure @nogc and nothrow? i don't think that you can make it `pure`, but you certainly can make it `nothrow`, `@nogc` and ctfe-able. it's

Cannot dispose const array?

2018-08-08 Thread Alexandru Ermicioi via Digitalmars-d-learn
Hi Dlang community! I've stumbled on an interesting issue with allocators. It seems that we can't get disposed of arrays with const or immutable data. Consider example below: Link: https://run.dlang.io/is/frnQI8 import std.stdio; import std.range; import

Re: float/double to string (pure nothrow @nogc)

2018-08-08 Thread ketmar via Digitalmars-d-learn
vit wrote: Hello, is in phobos some function which convert float/double to string and is pure @nogc and nothrow? i don't think that you can make it `pure`, but you certainly can make it `nothrow`, `@nogc` and ctfe-able. it's dangerous to go alone! take this[0]. [0]

Re: float/double to string (pure nothrow @nogc)

2018-08-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/8/18 1:08 PM, vit wrote: Hello, is in phobos some function which convert float/double to string and is pure @nogc and nothrow? Not one that I can see. formattedWrite doesn't seem to be pure. -Steve

float/double to string (pure nothrow @nogc)

2018-08-08 Thread vit via Digitalmars-d-learn
Hello, is in phobos some function which convert float/double to string and is pure @nogc and nothrow?

Re: Why does templated interface function return something different than final function?

2018-08-08 Thread Timoses via Digitalmars-d-learn
On Monday, 6 August 2018 at 14:27:01 UTC, Timoses wrote: On Thursday, 2 August 2018 at 20:35:57 UTC, Steven Schveighoffer wrote: Looking at the AST, it appears that toImpl doesn't recognize what inout(iface) is: toImpl!(string, inout(iface)) { @system string toImpl(ref inout(iface)

Re: countUntil's constraints

2018-08-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/7/18 10:28 PM, Nicholas Wilson wrote: On Wednesday, 8 August 2018 at 01:33:26 UTC, Steven Schveighoffer wrote: On 8/7/18 9:20 PM, Nicholas Wilson wrote: the first overload is ptrdiff_t countUntil(alias pred = "a == b", R, Rs...)(R haystack, Rs needles) if (isForwardRange!R && Rs.length

Re: if(int a = 0) lowered to "if (int a = (int a = 1;) , a)" ?

2018-08-08 Thread Alex via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 13:13:24 UTC, aliak wrote: Go here https://run.dlang.io/is/tJ4vXm and click on the AST button :) It shows you what the code turns in to after all the semantic passes. Yeah... no... I'm aware of this cool thing )) I thought you have a hidden source of

Re: if(int a = 0) lowered to "if (int a = (int a = 1;) , a)" ?

2018-08-08 Thread aliak via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 12:58:24 UTC, Alex wrote: On Wednesday, 8 August 2018 at 11:58:50 UTC, aliak wrote: Found this out while just looking at lowerings. How do you "look at lowerings"? Is there a list, I'm not aware of? ;) Go here https://run.dlang.io/is/tJ4vXm and click on the

Re: variable _param_0 cannot be read at compile time

2018-08-08 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 12:57:43 UTC, learnfirst1 wrote: Why this is a error ? ``` struct S { bool v; string x; } S* add(A...)(ref A a) { __gshared s = S(a); return } void main(){ auto p = add(true); } ``` test.d(9): Error: variable _param_0

Re: variable _param_0 cannot be read at compile time

2018-08-08 Thread learnfirst1 via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 12:57:43 UTC, learnfirst1 wrote: Why this is a error ? this code example can explain what I am try to do here: struct M { int i; S*[100] s; } struct S { M* mp; bool x; } S* add(A...)(ref A a) { __gshared s = S(a);

variable _param_0 cannot be read at compile time

2018-08-08 Thread learnfirst1 via Digitalmars-d-learn
Why this is a error ? ``` struct S { bool v; string x; } S* add(A...)(ref A a) { __gshared s = S(a); return } void main(){ auto p = add(true); } ``` test.d(9): Error: variable _param_0 cannot be read at compile time test.d(14): Error: template instance

Re: if(int a = 0) lowered to "if (int a = (int a = 1;) , a)" ?

2018-08-08 Thread Alex via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 11:58:50 UTC, aliak wrote: Found this out while just looking at lowerings. How do you "look at lowerings"? Is there a list, I'm not aware of? ;)

Re: if(int a = 0) lowered to "if (int a = (int a = 1;) , a)" ?

2018-08-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, August 8, 2018 5:58:50 AM MDT aliak via Digitalmars-d-learn wrote: > Found this out while just looking at lowerings. Wondering if > anyone knows the semantics involved here and where they are > documented? It's particularly useful when dealing with stuff like C functions that

if(int a = 0) lowered to "if (int a = (int a = 1;) , a)" ?

2018-08-08 Thread aliak via Digitalmars-d-learn
Found this out while just looking at lowerings. Wondering if anyone knows the semantics involved here and where they are documented? And, is there anyway to do it with multiple variables? I.e. if (int a = 0, int b = 0) { // ... } Cheers, - Ali

Re: Implicit conversion by return

2018-08-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, August 8, 2018 2:15:16 AM MDT Hakan Aras via Digitalmars-d- learn wrote: > Given this: > > struct Num > { > this(int a) {} > } > > Is there any reason why this works: > > Num n = 5; > > but this doesnt: > > Num funk() > { > return 5; > } > > > I understand that I can

Re: Implicit conversion by return

2018-08-08 Thread Hakan Aras via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 08:44:03 UTC, Alex wrote: return typeof(return)(5); Ah thanks, I was wondering if something like that exists. Still though, that's 16 extra characters that dont need to be there.

Re: Implicit conversion by return

2018-08-08 Thread Alex via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 08:15:16 UTC, Hakan Aras wrote: Given this: struct Num { this(int a) {} } Is there any reason why this works: Num n = 5; but this doesnt: Num funk() { return 5; } I understand that I can construct it explicitely, but that gets annoying quickly,

Implicit conversion by return

2018-08-08 Thread Hakan Aras via Digitalmars-d-learn
Given this: struct Num { this(int a) {} } Is there any reason why this works: Num n = 5; but this doesnt: Num funk() { return 5; } I understand that I can construct it explicitely, but that gets annoying quickly, especially with templates.