Re: function(pointer) as template argument, explicit template instantiation

2021-12-30 Thread Tejas via Digitalmars-d-learn
On Friday, 31 December 2021 at 00:57:26 UTC, kdevel wrote: ```dptr.d class R { } void foo (R r) { } alias fn = void function (R); void lyr (fn F) (R r) { } immutable fn foo_ptr = // line 14 pragma (msg, typeof (foo_ptr)); auto ptr = lyr!(foo_ptr);// line 17 ``` dmd reports: ```

function(pointer) as template argument, explicit template instantiation

2021-12-30 Thread kdevel via Digitalmars-d-learn
```dptr.d class R { } void foo (R r) { } alias fn = void function (R); void lyr (fn F) (R r) { } immutable fn foo_ptr = // line 14 pragma (msg, typeof (foo_ptr)); auto ptr = lyr!(foo_ptr);// line 17 ``` dmd reports: ``` immutable(void function(R)) dptr.d(14): Error: expression `& foo`

Re: std.signals: Why emit() not extist?

2021-12-30 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 30 December 2021 at 19:13:10 UTC, Marcone wrote: I get this error: Error: undefined identifier `emit`, did you mean function `exit`? You need to call it on the signal. class A { mixin Signal thing; } A a = new A; a.thing.emit();

Re: std.signals: Why emit() not extist?

2021-12-30 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 30 December 2021 at 19:13:10 UTC, Marcone wrote: I get this error: Error: undefined identifier `emit`, did you mean function `exit`? Did you `import std.signals`? — Bastiaan.

std.signals: Why emit() not extist?

2021-12-30 Thread Marcone via Digitalmars-d-learn
I get this error: Error: undefined identifier `emit`, did you mean function `exit`?

Re: print ubyte[] as (ascii) string

2021-12-30 Thread eugene via Digitalmars-d-learn
On Thursday, 30 December 2021 at 17:52:20 UTC, eugene wrote: everything as needed. Nevertheless, I do have zeroes in the buffer, so: ```d import std.stdio; import std.string; void main() { ubyte[8] b = [0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x0A, 0x00, 0x00]; /* "hello\n\0\0" */ char[]

Re: print ubyte[] as (ascii) string

2021-12-30 Thread eugene via Digitalmars-d-learn
On Thursday, 30 December 2021 at 17:43:14 UTC, Tejas wrote: I'm not at my computer anymore, could you please replace the `0x00` with `0x0A` and tell me if `strip` still doesn't work for my solution? Ok. I think the `fromstringz` is trimming the null bytes for you, making the `\n` the last

Re: print ubyte[] as (ascii) string

2021-12-30 Thread Tejas via Digitalmars-d-learn
On Thursday, 30 December 2021 at 17:31:27 UTC, eugene wrote: On Thursday, 30 December 2021 at 16:49:17 UTC, Tejas wrote: I _think_ the above code is correct, please verify Self-contained example: ```d import std.stdio; import std.string; void main() { ubyte[8] b = [0x68, 0x65, 0x6C,

Re: print ubyte[] as (ascii) string

2021-12-30 Thread eugene via Digitalmars-d-learn
On Thursday, 30 December 2021 at 17:16:10 UTC, Tejas wrote: I'll need to know the error message There is none, see example in my prev message because the following works: ```d import std; void main() { ubyte[] c ; c.length = 100; char[] arr = cast(char[])c[0 .. $];

Re: print ubyte[] as (ascii) string

2021-12-30 Thread eugene via Digitalmars-d-learn
On Thursday, 30 December 2021 at 16:49:17 UTC, Tejas wrote: I _think_ the above code is correct, please verify Self-contained example: ```d import std.stdio; import std.string; void main() { ubyte[8] b = [0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x0A, 0x00, 0x00]; /* "hello\n\0\0" */

Re: print ubyte[] as (ascii) string

2021-12-30 Thread Tejas via Digitalmars-d-learn
On Thursday, 30 December 2021 at 17:07:20 UTC, eugene wrote: On Thursday, 30 December 2021 at 16:49:17 UTC, Tejas wrote: ```d char[] s = cast(char[])ioCtx.buf[0 .. $];// please remember that in `[0 .. $]` last index is automatically `length - 1` but just buf[$] will be an error since there

Re: print ubyte[] as (ascii) string

2021-12-30 Thread eugene via Digitalmars-d-learn
On Thursday, 30 December 2021 at 16:49:17 UTC, Tejas wrote: ```d char[] s = cast(char[])ioCtx.buf[0 .. $];// please remember that in `[0 .. $]` last index is automatically `length - 1` but just buf[$] will be an error since there the actual `length` will be used ``` I _think_ the above code

Re: print ubyte[] as (ascii) string

2021-12-30 Thread eugene via Digitalmars-d-learn
On Thursday, 30 December 2021 at 09:34:27 UTC, eugene wrote: ```d char[] s = cast(char[])ioCtx.buf[0 .. strlen(cast(char*)ioCtx.buf.ptr) - 1]; // -1 is to eliminate terminating '\n' writefln("got '%s' from '%s:%d'", s, client.addr, client.port); ``` Is there some more concise/elegant way to do

Re: print ubyte[] as (ascii) string

2021-12-30 Thread Tejas via Digitalmars-d-learn
On Thursday, 30 December 2021 at 09:34:27 UTC, eugene wrote: I suspect the question was asked somewhere before. If so just give a link. Anyway: ```d class IoContext { ... ubyte[] buf; ... this(uint bufSize) { buf = new ubyte[bufSize]; } } ``` ```d class

Re: How to find how many places from left the dot appears in a flot/double?

2021-12-30 Thread rempas via Digitalmars-d-learn
On Thursday, 30 December 2021 at 11:17:39 UTC, afg45 wrote: See the https://en.wikipedia.org/wiki/Common_logarithm fpr the explanations. ``` import std.stdio, std.math; void main(string[] args) { alias numDigits = (f) => log10(f + 0.5).ceil(); } ``` Thanks a lot! However, I used the

Re: print ubyte[] as (ascii) string

2021-12-30 Thread eugene via Digitalmars-d-learn
On Thursday, 30 December 2021 at 16:00:59 UTC, Era Scarecrow wrote: The answer i ended up with was a quick conversion to a UTF in order to print it. Seems you might have to convert to Latin-1. For a moment I only have symbols from the lower half of ASCII table. I meant - can that be done as

Re: print ubyte[] as (ascii) string

2021-12-30 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 30 December 2021 at 09:34:27 UTC, eugene wrote: The buffer contains (ascii) string terminated with '\n'. In order to print it not as an array of numbers (buf is 1024 bytes long), but as usual string I do Few years ago i asked a similar question, not to do UTF-8 but to do Ascii.

Re: How to find how many places from left the dot appears in a flot/double?

2021-12-30 Thread afg45 via Digitalmars-d-learn
On Thursday, 30 December 2021 at 09:03:58 UTC, rempas wrote: Let's say that I have the following float/double: 137.837 How can I find how many places from left the dot appears? So in this example I want to take either three or four (depending on how you think it). Does anyone knows how I can

print ubyte[] as (ascii) string

2021-12-30 Thread eugene via Digitalmars-d-learn
I suspect the question was asked somewhere before. If so just give a link. Anyway: ```d class IoContext { ... ubyte[] buf; ... this(uint bufSize) { buf = new ubyte[bufSize]; } } ``` The buffer contains (ascii) string terminated with '\n'. In order to print it not

How to find how many places from left the dot appears in a flot/double?

2021-12-30 Thread rempas via Digitalmars-d-learn
Let's say that I have the following float/double: 137.837 How can I find how many places from left the dot appears? So in this example I want to take either three or four (depending on how you think it). Does anyone knows how I can do that and can explain it to me?