Re: implicit construction operator

2018-03-02 Thread Nick Treleaven via Digitalmars-d
On Monday, 26 February 2018 at 21:07:52 UTC, Meta wrote: This is possible in the language today using the implicit class construction feature of runtime variadic arrays: class VArray { Variant[] va; this(T...)(T ts) { foreach(t; ts) { va ~= Variant(t); } } } void test(VArray ta...)

Re: implicit construction operator

2018-02-28 Thread Nick Treleaven via Digitalmars-d
On Monday, 26 February 2018 at 21:36:49 UTC, ketmar wrote: aliak wrote: It makes libraries *much* more intuitive and expressive (C++ just got it wrong by choosing the wrong default). If you allow library authors to opt in instead of opt out then it becomes a conscious decision for one.

Re: implicit construction operator

2018-02-27 Thread Rubn via Digitalmars-d
On Monday, 26 February 2018 at 19:32:44 UTC, ketmar wrote: WebFreak001 wrote: Now before you would have only been able to do this: --- Nullable!Foo a; foo(a, Nullable!int(5)); --- but now you should also be able to do: --- Nullable!Foo x = null; Nullable!Foo y = 5; foo(null, 5); please

Re: implicit construction operator

2018-02-27 Thread TheFlyingFiddle via Digitalmars-d
On Monday, 26 February 2018 at 23:33:48 UTC, H. S. Teoh wrote: Not really a big deal (and auto kind of ruins it) but it would make stuff consistent between user types and built in ones. Not sure what you mean here. In a user type, if opBinary!"/" returns an int, then you still have the same

Re: implicit construction operator

2018-02-27 Thread aliak via Digitalmars-d
On Tuesday, 27 February 2018 at 13:36:30 UTC, ketmar wrote: aliak wrote: On Monday, 26 February 2018 at 21:34:21 UTC, ketmar wrote: aliak wrote: And if that's also a no no, how about char -> int. Or int -> float? Is ok? no, it is not ok. it was a mistake. it is now too late to fix it,

Re: implicit construction operator

2018-02-27 Thread ketmar via Digitalmars-d
aliak wrote: On Monday, 26 February 2018 at 21:34:21 UTC, ketmar wrote: aliak wrote: And if that's also a no no, how about char -> int. Or int -> float? Is ok? no, it is not ok. it was a mistake. it is now too late to fix it, but we can avoid doing more of the same kind. Oops, yeah, ok,

Re: implicit construction operator

2018-02-27 Thread biozic via Digitalmars-d
On Monday, 26 February 2018 at 19:25:06 UTC, WebFreak001 wrote: hi, I had an idea from using some C# which I think would be really cool in D. Basically allow modifying implicit construction of a type. Right now we only have struct opAssign/constructor implicit conversion, but this addition

Re: implicit construction operator

2018-02-26 Thread aliak via Digitalmars-d
On Monday, 26 February 2018 at 21:36:49 UTC, ketmar wrote: aliak wrote: It makes libraries *much* more intuitive and expressive (C++ just got it wrong by choosing the wrong default). If you allow library authors to opt in instead of opt out then it becomes a conscious decision for one.

Re: implicit construction operator

2018-02-26 Thread aliak via Digitalmars-d
On Monday, 26 February 2018 at 21:34:21 UTC, ketmar wrote: aliak wrote: And if that's also a no no, how about char -> int. Or int -> float? Is ok? no, it is not ok. it was a mistake. it is now too late to fix it, but we can avoid doing more of the same kind. Oops, yeah, ok, D char ...

Re: implicit construction operator

2018-02-26 Thread H. S. Teoh via Digitalmars-d
On Mon, Feb 26, 2018 at 09:45:03PM +, TheFlyingFiddle via Digitalmars-d wrote: > On Monday, 26 February 2018 at 21:30:09 UTC, aliak wrote: > > On Monday, 26 February 2018 at 19:32:44 UTC, ketmar wrote: > > > WebFreak001 wrote: > > And if that's also a no no, how about char -> int. Or int ->

Re: implicit construction operator

2018-02-26 Thread TheFlyingFiddle via Digitalmars-d
On Monday, 26 February 2018 at 21:30:09 UTC, aliak wrote: On Monday, 26 February 2018 at 19:32:44 UTC, ketmar wrote: WebFreak001 wrote: And if that's also a no no, how about char -> int. Or int -> float? Is ok? Maybe there're some valid arguments, to disallow it *completely* though?

Re: implicit construction operator

2018-02-26 Thread ketmar via Digitalmars-d
aliak wrote: It makes libraries *much* more intuitive and expressive (C++ just got it wrong by choosing the wrong default). If you allow library authors to opt in instead of opt out then it becomes a conscious decision for one. library authors can create overloads for various argument types.

Re: implicit construction operator

2018-02-26 Thread aliak via Digitalmars-d
On Monday, 26 February 2018 at 19:32:44 UTC, ketmar wrote: WebFreak001 wrote: Now before you would have only been able to do this: --- Nullable!Foo a; foo(a, Nullable!int(5)); --- but now you should also be able to do: --- Nullable!Foo x = null; Nullable!Foo y = 5; foo(null, 5); please

Re: implicit construction operator

2018-02-26 Thread ketmar via Digitalmars-d
aliak wrote: And if that's also a no no, how about char -> int. Or int -> float? Is ok? no, it is not ok. it was a mistake. it is now too late to fix it, but we can avoid doing more of the same kind.

Re: implicit construction operator

2018-02-26 Thread Meta via Digitalmars-d
On Monday, 26 February 2018 at 19:25:06 UTC, WebFreak001 wrote: Now this would be really useful for Variant: --- struct Variant { this(U)(U value) @implicit { ... } } void bar(Variant x, Variant y) {} Variant[] myObjects = [1, 2, "abc", new Node()]; Variant a = 4; bar(4, "asdf"); ---

Re: implicit construction operator

2018-02-26 Thread ketmar via Digitalmars-d
WebFreak001 wrote: Now before you would have only been able to do this: --- Nullable!Foo a; foo(a, Nullable!int(5)); --- but now you should also be able to do: --- Nullable!Foo x = null; Nullable!Foo y = 5; foo(null, 5); please no. such unobvious type conversions goes out of control

implicit construction operator

2018-02-26 Thread WebFreak001 via Digitalmars-d
hi, I had an idea from using some C# which I think would be really cool in D. Basically allow modifying implicit construction of a type. Right now we only have struct opAssign/constructor implicit conversion, but this addition would also add it to classes and make it even more convenient.