Re: Subtyping with alias this

2020-08-17 Thread novice3 via Digitalmars-d-learn
On Monday, 17 August 2020 at 14:43:27 UTC, H. S. Teoh wrote: What you need is to create an overload of toString that takes a FormatSpec parameter, so that you can decide what should be output for which format spec. Something along these lines: Sorry, i can't make it works. I tried ti read

Re: Subtyping with alias this

2020-08-18 Thread novice3 via Digitalmars-d-learn
On Tuesday, 18 August 2020 at 05:54:16 UTC, H. S. Teoh wrote: Here's a working example: Thank you, it works!

Re: Installing D on Fresh Windows 10 machine is a pain

2020-08-27 Thread novice3 via Digitalmars-d-learn
DMD x86 on Windows have no dependencies, just unpack .zip and use. It's a pitty, that DMD x64 depend on VS :(

Template: get function name

2020-08-17 Thread novice3 via Digitalmars-d-learn
Hello. I have wrapping Windows API functions, wich return 0 on success and erroro code on failure. I copy wenforce template as: ``` private T denforce(T, S)(T value, lazy S msg = null, string file = __FILE__, size_t line = __LINE__) { import core.sys.windows.winerror: NO_ERROR; import

Re: Template: get function name

2020-08-17 Thread novice3 via Digitalmars-d-learn
On Monday, 17 August 2020 at 08:55:49 UTC, Simen Kjærås wrote: Take the function as an alias parameter and wrap the entire call: Simen, for some reasons, your code dont respect api arg with "out" attribute. For example, i have ``` extern (Windows) DhcpEnumServers( in DWORD

Re: Template: get function name

2020-08-17 Thread novice3 via Digitalmars-d-learn
On Monday, 17 August 2020 at 10:11:29 UTC, MoonlightSentinel wrote: On Monday, 17 August 2020 at 09:59:21 UTC, novice3 wrote: On Monday, 17 August 2020 at 09:45:55 UTC, novice3 wrote: access violation occur. reduced code https://run.dlang.io/is/U58t9R The wrapper parameters don't inherit

Re: Template: get function name

2020-08-17 Thread novice3 via Digitalmars-d-learn
On Monday, 17 August 2020 at 08:55:49 UTC, Simen Kjærås wrote: Take the function as an alias parameter and wrap the entire call: auto denforce(alias fn, string file = __FILE__, size_t line = __LINE__, Args...)(Args args) Thank you, Simen!

Re: Template: get function name

2020-08-17 Thread novice3 via Digitalmars-d-learn
On Monday, 17 August 2020 at 09:45:55 UTC, novice3 wrote: access violation occur. reduced code https://run.dlang.io/is/U58t9R void test(out int x) { x = 42; } void call (alias fn, Args ...)(Args args) { fn(args); } void main(){ int a; a = 111; test(a); assert(a == 42); //

Subtyping with alias this

2020-08-17 Thread novice3 via Digitalmars-d-learn
Hello. I need subtype uint to store ipv4 address. It should be like ordinary uint, except conversion to string with %s format. My try https://run.dlang.io/is/fwTc0H failed on last assert: ``` struct IpV4Address { private uint ip; alias ip this; string toString() { import

Memory management

2020-09-29 Thread novice3 via Digitalmars-d-learn
Naive newbie question: Can we have (in theory) in D lang memory management like V lang? Quote: https://github.com/vlang/v/blob/master/doc/docs.md#memory-management "V doesn't use garbage collection or reference counting. The compiler cleans everything up during compilation. If your V

DMD: how to restore old unittest+main

2020-08-13 Thread novice3 via Digitalmars-d-learn
Hello. I don't use dub. I use Windows and *.d file association to compile small apps by dmd with "-i -unittest -g" switches. Now i update dmd, and found, that apps compiled with "-unittest" not runs main(). How i can restore old behaviour (run all unittests then main()) *without use

Re: DMD: how to restore old unittest+main

2020-08-13 Thread novice3 via Digitalmars-d-learn
On Thursday, 13 August 2020 at 08:30:44 UTC, Jonathan wrote: Is there a reason you need to run all unittests every time you want to run the program? App will be used by other peoples, and i will release it after developing without unittests. Release is rare action for me. Running while

Re: DMD: how to restore old unittest+main

2020-08-13 Thread novice3 via Digitalmars-d-learn
On Thursday, 13 August 2020 at 08:49:21 UTC, WebFreak001 wrote: Try version (unittest) extern(C) __gshared string[] rt_options = ["testmode=run-main" ]; Thanks! It works as needed.

Re: DMD: how to restore old unittest+main

2020-08-13 Thread novice3 via Digitalmars-d-learn
On Thursday, 13 August 2020 at 08:30:44 UTC, Jonathan wrote: Is there a reason you need to run all unittests every time you want to run the program? Starting app with unittests while develop - frequent event for me. Releasing app - rare event for me. I want do frequent action without efforts

Re: DMD: how to restore old unittest+main

2020-08-13 Thread novice3 via Digitalmars-d-learn
On Thursday, 13 August 2020 at 09:02:28 UTC, Nils Lankila wrote: programmatically, in a way it is already, but by calling function Better with compiler switch, may be...

Re: mysql-native Help required

2020-10-22 Thread novice3 via Digitalmars-d-learn
On Thursday, 22 October 2020 at 11:04:53 UTC, Vino wrote: class Connections { private Connection conn; auto constr = "host=localhost;port=3910;user=user;pwd=password#;db=testdb"; this.conn = new Connection(constr); } where Connections class constructor implemented?

Derived type

2021-03-30 Thread novice3 via Digitalmars-d-learn
Hello. When i adapt C code, i see new type creation: typedef void* Xobj; Or code like this: struct _Xobj; typedef struct _Xobj *Xobj; I want create derived type in D, found std.typecons.Typedef template, and write: alias Xobj = Typedef!(void*, (void*).init); But compiler use long

Re: Derived type

2021-04-01 Thread novice3 via Digitalmars-d-learn
On Thursday, 1 April 2021 at 12:07:17 UTC, WebFreak001 wrote: You can add a custom init value if you want to allow one: ```d enum Xobj : void* { init = null } ``` Thank you!

Re: Derived type

2021-03-31 Thread novice3 via Digitalmars-d-learn
On Wednesday, 31 March 2021 at 12:09:33 UTC, Basile B. wrote: yeah template instances are identified using the parameters identifiers, then the alias is just a syntactic shortcut to that, not producing a new symbol with a unique mangle... so, no way to generate struct with parametrized name

Re: Derived type

2021-03-30 Thread novice3 via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 21:53:34 UTC, Basile B. wrote: struct Typedef(TBase) { TBase payload; alias payload this; } alias Xobj = Typedef!(void*); This is how std.typecons.Typedef made, IMHO. The problem is this code generate struct with name "Typedef!(void*)", then compiler show

Is this bug ? format %(%)

2021-04-07 Thread novice3 via Digitalmars-d-learn
https://run.dlang.io/is/p4NVp8 ```d void main() { import std.stdio: writefln; string[] s = ["a", "b", "c"]; writefln("%(%s, %)", s); } ``` output ```d "a", "b", "c" ``` expected ```d a, b, c ``` there is extra quotes, wich not present in firmat specifier. is this bug, or i should

Re: How do I create classes dynamically?

2021-04-16 Thread novice3 via Digitalmars-d-learn
On Thursday, 15 April 2021 at 20:56:18 UTC, mw wrote: In response to user input? e.g. createObject(userInputString); what if user enter "Cthulhu"? if you say "i will check user input", then you know list of possible inputs, then you can use some compile-time technics. if you dont know

Enum template for cpp binding

2021-02-15 Thread novice3 via Digitalmars-d-learn
Hello. I want make binding for some CPP api. I have .h file with enums like: /// typedef enum { SOMEAPI_PHASE_A = 91, SOMEAPI_PHASE_B = 92, SOMEAPI_PHASE_C = 93 } someapiPhase; /// It used later in .cpp like: func(SOMEAPI_PHASE_A); I want .d file like this:

Re: Enum template for cpp binding

2021-02-15 Thread novice3 via Digitalmars-d-learn
On Monday, 15 February 2021 at 14:03:26 UTC, Paul Backus wrote: This will do most of it: Thank you Paul!

Analyze debug condition in template

2021-10-25 Thread novice3 via Digitalmars-d-learn
Hello. Need advice: Is it possible analyze "debug" condition in template, obtained from instantiation place? Like we using __LINE__ ? For example, i have template for logging: ```d void logf(string func = __FUNCTION__, int line = __LINE__, A...)(string fmt, A args) { // here i want

Re: Analyze debug condition in template

2021-10-25 Thread novice3 via Digitalmars-d-learn
i want to eliminate "debug(func1)" and "debug(func2)" from code: ```d debug = func1;// enable logging for func1 //debug = func2; // disable logging for func2 void func1() { ... debug(func1) logf("var1=%d", var1); ... } void func2() { ... debug(func2) logf("var1=%d",