Re: Deduce type of struct in function arguments

2018-08-21 Thread Seb via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 06:29:12 UTC, Andrey wrote: On Monday, 20 August 2018 at 17:45:25 UTC, Seb wrote: ... yet. Though you can vote for this DIP and show your support there: https://github.com/dlang/DIPs/pull/71 It even comes with an implementation in DMD already:

Cast to original type each argument in template pack

2018-08-21 Thread Andrey via Digitalmars-d-learn
Hello, I have a function: string format(string pattern, T...)(T value) { auto writer = appender!string(); writer.formattedWrite!pattern(convertToUnderlyingType(value)); //Tuple!T(value).expand.to!(OriginalType!T) return writer.data; } The "value" in this function can be any type

Re: Deduce type of struct in function arguments

2018-08-21 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 08:32:17 UTC, Seb wrote: How and where to vote? At the pull request via +1 and the upcoming "official" discussion of the PR. Except that there's no voting process for DIPs. The Community Review is not intended as a way to vote, simply to provide feedback

Re: Generically call a function on Variant's payload?

2018-08-21 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 20 August 2018 at 00:27:04 UTC, Nick Sabalausky (Abscissa) wrote: Suppose I've wrapped a Variant in a struct/class which ensures the Variant *only* ever contains types which satisfy a particular constraint (for example: isInputRange, or hasLength, etc...). Is there a way to call a

Re: D need an ORM library!

2018-08-21 Thread Russel Winder via Digitalmars-d-learn
On Tue, 2018-08-21 at 01:42 +, binghoo dang via Digitalmars-d-learn wrote: […] > > SQLAlchemy is very great, and I remember that > in D wiki has mentioned this, but the status is "Proposed Project > Mentors: TBA". SQLAlchemy is how SQL building and ORM should be done, in Python. For

Re: Deduce type of struct in function arguments

2018-08-21 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 17:45:25 UTC, Seb wrote: ... yet. Though you can vote for this DIP and show your support there: https://github.com/dlang/DIPs/pull/71 It even comes with an implementation in DMD already: https://github.com/dlang/dmd/pull/8460 How and where to vote?

Re: Generically call a function on Variant's payload?

2018-08-21 Thread Nick Sabalausky (Abscissa) via Digitalmars-d-learn
On 08/20/2018 10:57 PM, Jonathan M Davis wrote: Runtime reflection is theoretically possible in D, but it requires generating the appropriate stuff for every type involved so that the runtime stuff has something to work with. Java built all of that into the language and has the JVM to boot,

Re: Trouble with LDC2 and definition file to hide console?

2018-08-21 Thread Kagamin via Digitalmars-d-learn
MS has resource compiler too: https://docs.microsoft.com/en-us/windows/desktop/menurc/resource-compiler

Re: Trouble with LDC2 and definition file to hide console?

2018-08-21 Thread Kagamin via Digitalmars-d-learn
On Monday, 20 August 2018 at 13:42:58 UTC, spikespaz wrote: I would also like to know how to add a PNG or ICO file to my compiled executable. I have icons in the resolutions of 16, 32, 64, 128, 256. Currently I'm adding them in using GitHub's RCEDIT tool (https://github.com/electron/rcedit)

Re: Dub and it's build directory

2018-08-21 Thread Petar via Digitalmars-d-learn
On Monday, 20 August 2018 at 18:59:23 UTC, Russel Winder wrote: Hi, [...] Hi Russel, So the questions are: 1. How does Dub find the compiler version number, in this case 2.081, given that neither DMD or LDC seem to have a way of delivering only the version number. The __VERSION__ [1]

Re: D need an ORM library!

2018-08-21 Thread bauss via Digitalmars-d-learn
On Monday, 20 August 2018 at 02:30:16 UTC, binghoo dang wrote: hi, I thinks D need an ORM library for Sqlite/Mysql/PostgreSQL, entity currently support all the three targets, but entity's API is too complex and cumbersome for using. Is there a more light-weight and simpler implementation

Re: Cast to original type each argument in template pack

2018-08-21 Thread Alex via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 08:08:58 UTC, Andrey wrote: Hello, I have a function: string format(string pattern, T...)(T value) { auto writer = appender!string(); writer.formattedWrite!pattern(convertToUnderlyingType(value)); //Tuple!T(value).expand.to!(OriginalType!T) return

Re: Deduce type of struct in function arguments

2018-08-21 Thread Seb via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 08:47:53 UTC, Mike Parker wrote: On Tuesday, 21 August 2018 at 08:32:17 UTC, Seb wrote: How and where to vote? At the pull request via +1 and the upcoming "official" discussion of the PR. Except that there's no voting process for DIPs. The Community

Re: Auto keyword and when to use it

2018-08-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/20/18 9:15 PM, Mike Parker wrote: I tend to use type inference liberally, almost always with const/immutbale locals, though I tend to use auto only when the type name is longer than four characters. For me, it's a nice way to save keystrokes. Some take a dim view of that approach and

Re: Coreect way to create delegate for struct method.

2018-08-21 Thread Alex via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 21:29:38 UTC, Andrey wrote: Hello, This is a code: import std.stdio; struct Test { static Test opCall() { Test test; test.handler = return test; } void one() const { writeln("In handler: Address = ", , "; Text = ", text); }

Re: Deduce type of struct in function arguments

2018-08-21 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 14:56:21 UTC, Seb wrote: I'm aware, but we don't have any other process for people to show their support for a DIP, do we? And for DMD/Druntime/Phobos etc. having a bunch of +1 helps a PR to move faster as we as reviewers can thus realize that this is sth.

Re: Deduce type of struct in function arguments

2018-08-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, August 21, 2018 6:56:06 PM MDT Mike Parker via Digitalmars-d- learn wrote: > On Tuesday, 21 August 2018 at 14:56:21 UTC, Seb wrote: > > I'm aware, but we don't have any other process for people to > > show their support for a DIP, do we? > > > > > > And for DMD/Druntime/Phobos etc.

Re: Auto keyword and when to use it

2018-08-21 Thread Jim Balter via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 18:18:25 UTC, QueenSvetlana wrote: On Tuesday, 21 August 2018 at 16:15:32 UTC, XavierAP wrote: Only if someone likes "Type x = new Type()" instead of "auto x = new Type()" I would say they're clearly wrong. As you stated it's up to the programmer to decided. I'm

Re: Auto keyword and when to use it

2018-08-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, August 21, 2018 9:04:31 AM MDT Steven Schveighoffer via Digitalmars-d-learn wrote: > On 8/20/18 9:15 PM, Mike Parker wrote: > > I tend to use type inference liberally, almost always with > > const/immutbale locals, though I tend to use auto only when the type > > name is longer than

Re: Generically call a function on Variant's payload?

2018-08-21 Thread Nick Sabalausky (Abscissa) via Digitalmars-d-learn
On 08/21/2018 03:27 PM, Steven Schveighoffer wrote: If you examine how the code for variant works, it's quite clever. It establishes a "handler" that is generated with full compile-time type info available when the value is *assigned*, but then cast to a function taking a void pointer and an

Coreect way to create delegate for struct method.

2018-08-21 Thread Andrey via Digitalmars-d-learn
Hello, This is a code: import std.stdio; struct Test { static Test opCall() { Test test; test.handler = return test; } void one() const { writeln("In handler: Address = ", , "; Text = ", text); } void execute() { text = "Inited!";

Re: Are properties mature enough?

2018-08-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, August 21, 2018 1:46:31 PM MDT Jim Balter via Digitalmars-d- learn wrote: > That's a lot of detail. The bottom line is that the warning in > the spec is completely wrong and should be removed -- using > property functions is not discouraged, nor is @property. > @property should be

Re: Auto keyword and when to use it

2018-08-21 Thread QueenSvetlana via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 18:44:15 UTC, Jim Balter wrote: Python is not statically typed; D is. Why are you talking about Python? You asked whether D's auto is like C#'s var ... it is, but it doesn't have C#'s pointless restriction of not being allowed for non-local declarations. I think

Re: Auto keyword and when to use it

2018-08-21 Thread QueenSvetlana via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 16:15:32 UTC, XavierAP wrote: Only if someone likes "Type x = new Type()" instead of "auto x = new Type()" I would say they're clearly wrong. As you stated it's up to the programmer to decided. I'm in favor of Type x = new Type() because when it comes to

Re: Generically call a function on Variant's payload?

2018-08-21 Thread Nick Sabalausky (Abscissa) via Digitalmars-d-learn
On 08/21/2018 03:03 AM, Nicholas Wilson wrote: On Monday, 20 August 2018 at 00:27:04 UTC, Nick Sabalausky (Abscissa) wrote: Suppose I've wrapped a Variant in a struct/class which ensures the Variant *only* ever contains types which satisfy a particular constraint (for example: isInputRange, or

Re: Auto keyword and when to use it

2018-08-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, August 21, 2018 12:22:42 PM MDT QueenSvetlana via Digitalmars-d- learn wrote: > On Monday, 20 August 2018 at 17:55:11 UTC, JN wrote: > > class Foo > > { > > > > auto bar; > > > > } > > > > because now the compiler doesn't know what type 'bar' is > > supposed to be. > > Just to

Re: Are properties mature enough?

2018-08-21 Thread Jim Balter via Digitalmars-d-learn
On Monday, 20 August 2018 at 00:49:02 UTC, Jonathan M Davis wrote: On Sunday, August 19, 2018 12:32:17 PM MDT QueenSvetlana via Digitalmars-d- learn wrote: In the D Style Guide, it says: Properties https://dlang.org/dstyle.html#properties Functions should be property functions whenever

Re: Auto keyword and when to use it

2018-08-21 Thread QueenSvetlana via Digitalmars-d-learn
On Monday, 20 August 2018 at 17:55:11 UTC, JN wrote: class Foo { auto bar; } because now the compiler doesn't know what type 'bar' is supposed to be. Just to clarify, even if I set bar in the constructor, I can't declare it with auto first, correct? I would have to declare a specific

Re: ushort + ushort = int?

2018-08-21 Thread Jim Balter via Digitalmars-d-learn
On Monday, 20 August 2018 at 08:34:56 UTC, Andrey wrote: Hello, Here is a code that you can execute using online compiler https://run.dlang.io/: import std.stdio; void main() { ushort first = 5; ushort second = 1000; ushort result = first + second; writeln(result); } I hae

Re: Generically call a function on Variant's payload?

2018-08-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/21/18 3:11 PM, Nick Sabalausky (Abscissa) wrote: On 08/21/2018 03:03 AM, Nicholas Wilson wrote: On Monday, 20 August 2018 at 00:27:04 UTC, Nick Sabalausky (Abscissa) wrote: Suppose I've wrapped a Variant in a struct/class which ensures the Variant *only* ever contains types which satisfy

Re: Auto keyword and when to use it

2018-08-21 Thread XavierAP via Digitalmars-d-learn
On Monday, 20 August 2018 at 17:52:17 UTC, QueenSvetlana wrote: So I can't declare class level variables with auto, correct? only local method variables? One difference between D's auto and C#'s var or C++'s auto is that the latter languages allow automatically typed declarations only for

Re: Dub and it's build directory

2018-08-21 Thread Seb via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 12:31:20 UTC, Petar Kirov [ZombineDev] wrote: What Dub does is what it calls "platform probing" [3]. It creates a temporary .d file containing various `pragma (msg, ..)` statements that output information to stderr during compilation. Of course the question is