Initialise non-copyable, non-default-constrauctable member struct

2018-07-27 Thread Peter Particle via Digitalmars-d-learn
Question is related to this: https://dlang.org/spec/struct.html#disable_default_construction struct S { int x; @disable this(); // Disables default construction @disable this(this); // Disable copying this(int v) { x = v; } } struct T { float y; S s; @disable thi

Re: Initialise non-copyable, non-default-constrauctable member struct

2018-07-27 Thread aliak via Digitalmars-d-learn
On Friday, 27 July 2018 at 12:11:37 UTC, Peter Particle wrote: Question is related to this: https://dlang.org/spec/struct.html#disable_default_construction struct S { int x; @disable this(); // Disables default construction @disable this(this); // Disable copying this(int v)

Re: Initialise non-copyable, non-default-constrauctable member struct

2018-07-27 Thread aliak via Digitalmars-d-learn
On Friday, 27 July 2018 at 13:05:07 UTC, aliak wrote: https://run.dlang.io/is/lLrUiq Sorry: https://run.dlang.io/is/20FUoj

How come isMutable returns true for structs that cannot be modified

2018-07-27 Thread aliak via Digitalmars-d-learn
import std.traits: isMutable; struct S { immutable int i = 3; } pragma(msg, isMutable!S); void main() { S s; s = S(); } And is there a trait that takes the transitivity of immutability in to account? Cheers, - Ali

Re: How to get an inout constructor working with a template wrapper

2018-07-27 Thread aliak via Digitalmars-d-learn
On Monday, 23 July 2018 at 14:46:32 UTC, Timoses wrote: On Monday, 23 July 2018 at 12:02:58 UTC, aliak wrote: [...] Both of these seem to work (as you pointed out) // immutable(W!int) auto si = wrap!(int)(cast(immutable)3); // or wrap(cast(immutable)3); // W!(immutable(int))

Re: How to get an inout constructor working with a template wrapper

2018-07-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/23/18 8:02 AM, aliak wrote: On Sunday, 22 July 2018 at 23:11:09 UTC, Ali Çehreli wrote: Without much confidence on my side, first, I think you need to make the constructor parameter inout(T) as well. Otherwise, you may be making a const(W!T) initialized with a non-const T. After that, I

Re: How to get an inout constructor working with a template wrapper

2018-07-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/27/18 9:29 AM, aliak wrote: Ok, thanks to Simen from another post [0], I just figured out what the correct constructor and factory method for a template wrapper should be: https://run.dlang.io/is/S4vHzL struct W(T) {     T val;     this(U : T, this This)(auto ref U val) {     this.

Re: How come isMutable returns true for structs that cannot be modified

2018-07-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/27/18 9:10 AM, aliak wrote: import std.traits: isMutable; struct S {     immutable int i = 3; } pragma(msg, isMutable!S); void main() {     S s;     s = S(); } isMutable only takes the type into account, it doesn't look to see if all the internals are mutable. It literally is this:

Re: How to avoid inout type constructor with Optional type wrapper undoing string type

2018-07-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/23/18 2:39 PM, aliak wrote: Hi, I'm playing around with an Optional wrapper type. It stores a type T and a bool that defines whether a value is defined or not: struct Optional(T) {   T value;   bool defined = false;   this(U : T)(auto ref inout(U) value) inout {     this.value = valu

Re: How come isMutable returns true for structs that cannot be modified

2018-07-27 Thread aliak via Digitalmars-d-learn
On Friday, 27 July 2018 at 14:48:06 UTC, Steven Schveighoffer wrote: On 7/27/18 9:10 AM, aliak wrote: import std.traits: isMutable; struct S {     immutable int i = 3; } pragma(msg, isMutable!S); void main() {     S s;     s = S(); } isMutable only takes the type into account, it doesn't

Re: Initialise non-copyable, non-default-constrauctable member struct

2018-07-27 Thread Peter Particle via Digitalmars-d-learn
On Friday, 27 July 2018 at 13:06:10 UTC, aliak wrote: On Friday, 27 July 2018 at 13:05:07 UTC, aliak wrote: https://run.dlang.io/is/lLrUiq Sorry: https://run.dlang.io/is/20FUoj Thanks, you are right, but it seems that I have reduced my issue too much, as it still does not work with my actua

A vibe.d thing

2018-07-27 Thread Russel Winder via Digitalmars-d-learn
I have posted to the vibe.d forum, but I hate forums, and it looks like a months worth of questions haven't been read yet, so please excuse repeating here – I need an fairly definitive answer pdq in order to finish my answer to the CVu Code Critique 112. The deadline is in three days. http://forum

Re: A vibe.d thing

2018-07-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/27/18 3:02 PM, Russel Winder wrote: I have posted to the vibe.d forum, but I hate forums, and it looks like a months worth of questions haven't been read yet, so please excuse repeating here – I need an fairly definitive answer pdq in order to finish my answer to the CVu Code Critique 112. T

Re: A vibe.d thing

2018-07-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/27/18 3:18 PM, Steven Schveighoffer wrote: On 7/27/18 3:02 PM, Russel Winder wrote: I have posted to the vibe.d forum, but I hate forums, and it looks like a months worth of questions haven't been read yet, so please excuse repeating here – I need an fairly definitive answer pdq in order to

Re: A vibe.d thing

2018-07-27 Thread Russel Winder via Digitalmars-d-learn
On Fri, 2018-07-27 at 15:25 -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: […] > > Oh, it looks like you specified once. Hm... that seems to me like it > should work. > > Looks like IOMode is ignored: > > https://github.com/vibe-d/vibe.d/blob/a9589d955f10bd076a67d47ace0c78c > fd3aa8

Re: A vibe.d thing

2018-07-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/27/18 3:44 PM, Russel Winder wrote: On Fri, 2018-07-27 at 15:25 -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: […] Oh, it looks like you specified once. Hm... that seems to me like it should work. Looks like IOMode is ignored: https://github.com/vibe-d/vibe.d/blob/a9589d955f1