Re: Convert array to custom type when passing function argument

2019-04-19 Thread Ali Çehreli via Digitalmars-d-learn
On 04/17/2019 05:21 PM, Stefanos Baziotis wrote: > On Wednesday, 17 April 2019 at 23:44:42 UTC, Adam D. Ruppe wrote: >>explicit Test(const char* foo) {} // this opts out of the cool >> thing above > Actually, I asked initially because in C++ you can do the thing I > described. > I thought

Re: Convert array to custom type when passing function argument

2019-04-17 Thread Stefanos Baziotis via Digitalmars-d-learn
On Wednesday, 17 April 2019 at 23:44:42 UTC, Adam D. Ruppe wrote: In C++, if you define a struct/class, and constructors apply for this. struct Test { Test(const char* foo) {} }; void cool(Test t) {} cool("string"); // works That works in C++, unless you mark that constructor with

Re: Convert array to custom type when passing function argument

2019-04-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 17 April 2019 at 23:26:16 UTC, Stefanos Baziotis wrote: I argue C++'s mistake was *out-out* implicit construction What do you mean by out-out? In C++, if you define a struct/class, and constructors apply for this. struct Test { Test(const char* foo) {} }; void cool(Test

Re: Convert array to custom type when passing function argument

2019-04-17 Thread Stefanos Baziotis via Digitalmars-d-learn
On Wednesday, 17 April 2019 at 16:33:17 UTC, Adam D. Ruppe wrote: [...] Thanks for the info! I argue C++'s mistake was *out-out* implicit construction What do you mean by out-out? - Stefanos

Re: Convert array to custom type when passing function argument

2019-04-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 17 April 2019 at 15:23:06 UTC, Stefanos Baziotis wrote: Sorry if this has been asked again, I didn't find anything. Do we know the reason why it is not supported? Basically implicit construction was considered a mistake in C++ and D didn't want to repeat that mistake. Most code

Re: Convert array to custom type when passing function argument

2019-04-17 Thread Stefanos Baziotis via Digitalmars-d-learn
On Wednesday, 17 April 2019 at 12:48:52 UTC, Adam D. Ruppe wrote: This is the "implicit construction" I sometimes talk about and D doesn't support it, by design (alas). Sorry if this has been asked again, I didn't find anything. Do we know the reason why it is not supported? There's

Re: Convert array to custom type when passing function argument

2019-04-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 17 April 2019 at 12:20:49 UTC, Stefanos Baziotis wrote: I want to be able to make it work array-like to have compact function calls. Something like this: test([1,2,3]); This is the "implicit construction" I sometimes talk about and D doesn't support it, by design (alas).

Convert array to custom type when passing function argument

2019-04-17 Thread Stefanos Baziotis via Digitalmars-d-learn
I have a custom Buf struct (working as a simple vector) struct Buf(T) { size_t cap, len; T *data; @nogc this(T[] arr) { reserve(arr.length); foreach(item; arr) { push(item); } } ... }; And I have a function like this: void