Re: Cannot call @system funciton (stdout)

2020-08-17 Thread Kagamin via Digitalmars-d-learn
On Sunday, 16 August 2020 at 18:13:07 UTC, Anonymouse wrote: Just as a drive-by comment, the main stdio thing I came across that I couldn't do from within @safe was stdout.flush(), which I need to call manually for Cygwin terminals and some terminals embedded in editors (vscode). If someone kno

Re: Subtyping with alias this

2020-08-17 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: Subtyping with alias this

2020-08-17 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 18, 2020 at 05:34:58AM +, novice3 via Digitalmars-d-learn wrote: [...] > The problem is: > if i use fmt.spec in overloaded toString(), > when i get error "phobos/std/format.d(2243): Error: no property ip for > type onlineapp.IpV4Address" Here's a working example: -

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 for

Re: How to sort a multidimensional ndslice?

2020-08-17 Thread 9il via Digitalmars-d-learn
The following code just sorts each row: -- /+dub.sdl: dependency "mir-algorithm" version="~>3.9.24" +/ import mir.ndslice; import mir.ndslice.sorting; import mir.algorithm.iteration: each; void main() { // fuse, not sliced if you use an array of arrays for argument auto a = [[1,

How to sort a multidimensional ndslice?

2020-08-17 Thread Arredondo via Digitalmars-d-learn
I want to sort a two-dimensional ndslice by its columns according to some predefined predicate. What I mean is _not_ sorting the contents of each column individually, but instead to reorder the entire columns of the matrix so that they are sorted according to some "greater than" function. H

Re: Can a call to pragma(msg, __FILE__, ...) be mixin templatized?

2020-08-17 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 17 August 2020 at 21:18:41 UTC, Per Nordlöw wrote: I'm using pragma(msg, __FILE__, "(", __LINE__, ",1): Debug: ", "A useful debug message"); to print compile-time information formatted as standard compiler diagnostics. These are picked up by Emacs Flycheck and overlayed in t

Can a call to pragma(msg, __FILE__, ...) be mixin templatized?

2020-08-17 Thread Per Nordlöw via Digitalmars-d-learn
I'm using pragma(msg, __FILE__, "(", __LINE__, ",1): Debug: ", "A useful debug message"); to print compile-time information formatted as standard compiler diagnostics. These are picked up by Emacs Flycheck and overlayed in the editor and listen in the *Flycheck errors* buffer. Very con

Re: vibe.d and my first web service

2020-08-17 Thread aberba via Digitalmars-d-learn
On Thursday, 13 August 2020 at 09:54:06 UTC, Mr. Backup wrote: On Wednesday, 12 August 2020 at 13:46:06 UTC, James Blachly wrote: Unfortunately the problem still occurs with Vibe.d 0.9.0 IMO **this is the single most important problem to fix** for vibe.d -- if the most basic of examples (inde

Re: Subtyping with alias this

2020-08-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 17, 2020 at 02:29:47PM +, novice3 via Digitalmars-d-learn wrote: [...] > ``` > struct IpV4Address > { > private uint ip; > alias ip this; > > string toString() > { > import std.conv: to; > return to!string((ip >>> 24) & 0xFF) ~ "." ~ >to!string((ip >>> 1

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 std.conv:

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 th

Re: Template: get function name

2020-08-17 Thread MoonlightSentinel via Digitalmars-d-learn
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 the storage classes from the wrapped function. Try using std.traits.P

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); // O

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 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 Simen Kjærås via Digitalmars-d-learn
On Monday, 17 August 2020 at 08:07:32 UTC, novice3 wrote: 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__) {

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 std