Re: print ubyte[] as (ascii) string

2021-12-31 Thread Steven Schveighoffer 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]; } } ``` The buffer contains

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

2021-12-31 Thread kdevel via Digitalmars-d-learn
On Friday, 31 December 2021 at 12:36:46 UTC, H. S. Teoh wrote: ``` void lyr(alias Fn)(ref R r) { Fn(r); } ``` Thanks! That helped me reinvent the engine.

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

2021-12-31 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 31, 2021 at 11:52:21AM +, kdevel via Digitalmars-d-learn wrote: [...] > That is what I want to do. The function template lyr shall be > (explicitly) instantiated in order to put the resulting function > pointer into an AA. The call signature of lyr!(foo) and foo must be > the same.

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

2021-12-31 Thread kdevel via Digitalmars-d-learn
On Friday, 31 December 2021 at 09:01:10 UTC, data pulverizer wrote: On Friday, 31 December 2021 at 00:57:26 UTC, kdevel wrote: Pointers are runtime entities and are not suitable template parameters (compile time). The address of a function does not change at runtime. The question is: Can

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

2021-12-31 Thread kdevel via Digitalmars-d-learn
On Friday, 31 December 2021 at 03:02:08 UTC, Tejas wrote: [...] Is it okay to use template parameter instead of **template value** parameter? ```d class R { } void foo (R r) { } void lyr (fp_type, R) (fp_type fp, R r) { } pragma (msg, typeof ()); R r; void main(){ auto foo_ptr =

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

2021-12-31 Thread data pulverizer 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: ```