Re: How to use core.vararg to print D variadic arguments and their types without using ! (template instantiation)?

2023-09-18 Thread BoQsc via Digitalmars-d-learn
Note that this doesn't work in gdc. The templated version is actually more akin to what C does. Yeah it does not seem to work in gdc when tested using https://d.godbolt.org/ The errors produced: ``` :11:12: error: none of the overloads of template 'core.stdc.stdarg.va_arg' are callable us

Re: How to use core.vararg to print D variadic arguments and their types without using ! (template instantiation)?

2023-09-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/15/23 4:14 PM, Basile B. wrote: On Thursday, 14 September 2023 at 15:19:29 UTC, BoQsc wrote: https://dlang.org/phobos/core_vararg.html The common way to use **va_arg** is `va_arg!(int)(_argptr);` What would be the alternative way or syntax that behave exactly the same way, even if more ve

Re: How to use core.vararg to print D variadic arguments and their types without using ! (template instantiation)?

2023-09-15 Thread Basile B. via Digitalmars-d-learn
On Thursday, 14 September 2023 at 15:19:29 UTC, BoQsc wrote: https://dlang.org/phobos/core_vararg.html The common way to use **va_arg** is `va_arg!(int)(_argptr);` What would be the alternative way or syntax that behave exactly the same way, even if more verbose? `va_arg!(int)(_argptr)

How to use core.vararg to print D variadic arguments and their types without using ! (template instantiation)?

2023-09-14 Thread BoQsc via Digitalmars-d-learn
https://dlang.org/phobos/core_vararg.html The common way to use **va_arg** is `va_arg!(int)(_argptr);` What would be the alternative way or syntax that behave exactly the same way, even if more verbose? `va_arg!(int)(_argptr);` is taken from an example in: https://dlang.org/spec/functio

Re: Weird template instantiation speed?

2023-07-09 Thread IchorDev via Digitalmars-d-learn
On Sunday, 9 July 2023 at 14:49:39 UTC, Steven Schveighoffer wrote: This is probably a bug somewhere, 4 seconds is too much. A reduced test case would be helpful. But I wanted to note, inside a struct template, the template name (by itself) is equivalent to the current instantiation. So jus

Re: Weird template instantiation speed?

2023-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/23 7:54 AM, IchorDev wrote: While working on some new bindings, I've discovered that if `opAssign` in a struct template "`BindingTempl(T)`" has the return type "`BindingTempl!T` then it adds about 4 seconds to the compile time per instantiation of `BindingTempl`. The added compile time i

Weird template instantiation speed?

2023-07-09 Thread IchorDev via Digitalmars-d-learn
While working on some new bindings, I've discovered that if `opAssign` in a struct template "`BindingTempl(T)`" has the return type "`BindingTempl!T` then it adds about 4 seconds to the compile time per instantiation of `BindingTempl`. The added compile time is much lower if a function other th

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 func

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 (&foo)); R r; void main(){ auto foo_ptr = &foo;

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 = &foo; // line 14 pragma (msg, typeof (foo_ptr)); auto ptr = lyr!(foo_ptr);// line 17 ``` dmd reports: ``` im

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 = &foo; // line 14 pragma (msg, typeof (foo_ptr)); auto ptr = lyr!(foo_ptr);// line 17 ``` dmd reports: ``` im

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 = &foo; // 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 `& f

Re: 0 cost template instantiation

2021-09-29 Thread Hipreme via Digitalmars-d-learn
On Thursday, 30 September 2021 at 03:21:51 UTC, jfondren wrote: On Thursday, 30 September 2021 at 03:13:28 UTC, jfondren wrote: As provided, loadSymbol without the "static if": 965K libhipengine_api.a with `mixin(loadSymbol("name"))` instead of a template: 749K libhipengine_api.a The differ

Re: 0 cost template instantiation

2021-09-29 Thread jfondren via Digitalmars-d-learn
On Thursday, 30 September 2021 at 03:13:28 UTC, jfondren wrote: As provided, loadSymbol without the "static if": 965K libhipengine_api.a with `mixin(loadSymbol("name"))` instead of a template: 749K libhipengine_api.a The difference goes down to 66K vs. 60K with `dub -brelease --compiler=gdc

Re: 0 cost template instantiation

2021-09-29 Thread jfondren via Digitalmars-d-learn
On Thursday, 30 September 2021 at 02:31:50 UTC, Hipreme wrote: https://github.com/MrcSnm/HipremeEngine/tree/hotload/api You may try messing at the module api.graphics.g2d.renderer2d There is a function called initG2D Try changing it from loadSymbols to each one loadSymbol. You can just dub at

Re: 0 cost template instantiation

2021-09-29 Thread Hipreme via Digitalmars-d-learn
On Thursday, 30 September 2021 at 02:22:35 UTC, jfondren wrote: On Thursday, 30 September 2021 at 01:44:57 UTC, jfondren wrote: On Thursday, 30 September 2021 at 01:09:47 UTC, Hipreme wrote: I have a template function that all it does is given a symbol, it loads a dll for its type + its name:

Re: 0 cost template instantiation

2021-09-29 Thread jfondren via Digitalmars-d-learn
On Thursday, 30 September 2021 at 01:44:57 UTC, jfondren wrote: On Thursday, 30 September 2021 at 01:09:47 UTC, Hipreme wrote: I have a template function that all it does is given a symbol, it loads a dll for its type + its name: ``` void loadSymbol(alias s, string symName = "")() { st

Re: 0 cost template instantiation

2021-09-29 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 30 September 2021 at 02:09:50 UTC, Hipreme wrote: I could reduce by almost 100kb of code by instead of using the former option, I use: yes this is what id o you can list the Ts in an interface too. see my simpledisplay.d `interface GL` for example I do still don't think that th

Re: 0 cost template instantiation

2021-09-29 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 30 September 2021 at 02:02:19 UTC, Hipreme wrote: Instead of writing myFunction = cast(typeof(myFunction))_loadSymbol(_dll, "myFunction"); I could write loadSymbol!myFunction; But if no other way is found of doing that, I will do the massive rewriting. --- void function() x

Re: 0 cost template instantiation

2021-09-29 Thread Hipreme via Digitalmars-d-learn
On Thursday, 30 September 2021 at 01:09:47 UTC, Hipreme wrote: I have a template function that all it does is given a symbol, it loads a dll for its type + its name: ``` void loadSymbol(alias s, string symName = "")() { static if(symName == "") s = cast(typeof(s))_loadSy

Re: 0 cost template instantiation

2021-09-29 Thread Basile B. via Digitalmars-d-learn
On Thursday, 30 September 2021 at 02:02:19 UTC, Hipreme wrote: On Thursday, 30 September 2021 at 01:56:42 UTC, Basile B. wrote: On Thursday, 30 September 2021 at 01:09:47 UTC, Hipreme wrote: I have a template function that all it does is given a symbol, it loads a dll for its type + its name:

Re: 0 cost template instantiation

2021-09-29 Thread Hipreme via Digitalmars-d-learn
On Thursday, 30 September 2021 at 01:56:42 UTC, Basile B. wrote: On Thursday, 30 September 2021 at 01:09:47 UTC, Hipreme wrote: I have a template function that all it does is given a symbol, it loads a dll for its type + its name: ``` void loadSymbol(alias s, string symName = "")() { s

Re: 0 cost template instantiation

2021-09-29 Thread Basile B. via Digitalmars-d-learn
On Thursday, 30 September 2021 at 01:09:47 UTC, Hipreme wrote: I have a template function that all it does is given a symbol, it loads a dll for its type + its name: ``` void loadSymbol(alias s, string symName = "")() { static if(symName == "") s = cast(typeof(s))_loadSy

Re: 0 cost template instantiation

2021-09-29 Thread jfondren via Digitalmars-d-learn
On Thursday, 30 September 2021 at 01:09:47 UTC, Hipreme wrote: I have a template function that all it does is given a symbol, it loads a dll for its type + its name: ``` void loadSymbol(alias s, string symName = "")() { static if(symName == "") s = cast(typeof(s))_loadSy

0 cost template instantiation

2021-09-29 Thread Hipreme via Digitalmars-d-learn
I have a template function that all it does is given a symbol, it loads a dll for its type + its name: ``` void loadSymbol(alias s, string symName = "")() { static if(symName == "") s = cast(typeof(s))_loadSymbol(_dll, (s.stringof~"\0").ptr); else

Re: D compiler equivilent of "gcc -E" for debug/view template instantiation(generated) code?

2021-07-30 Thread dangbinghoo via Digitalmars-d-learn
On Friday, 30 July 2021 at 10:20:36 UTC, Stefan Koch wrote: On Friday, 30 July 2021 at 09:30:13 UTC, Mike Parker wrote: On Friday, 30 July 2021 at 08:38:24 UTC, dangbinghoo wrote: but, where's these switch option documented? it seems it not appears in dmd --help or man dmd, or online documen

Re: D compiler equivilent of "gcc -E" for debug/view template instantiation(generated) code?

2021-07-30 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 30 July 2021 at 09:30:13 UTC, Mike Parker wrote: On Friday, 30 July 2021 at 08:38:24 UTC, dangbinghoo wrote: but, where's these switch option documented? it seems it not appears in dmd --help or man dmd, or online document https://dlang.org/dmd-linux.html That's what he meant

Re: D compiler equivilent of "gcc -E" for debug/view template instantiation(generated) code?

2021-07-30 Thread dangbinghoo via Digitalmars-d-learn
On Friday, 30 July 2021 at 09:30:13 UTC, Mike Parker wrote: On Friday, 30 July 2021 at 08:38:24 UTC, dangbinghoo wrote: but, where's these switch option documented? it seems it not appears in dmd --help or man dmd, or online document https://dlang.org/dmd-linux.html That's what he meant

Re: D compiler equivilent of "gcc -E" for debug/view template instantiation(generated) code?

2021-07-30 Thread Mike Parker via Digitalmars-d-learn
On Friday, 30 July 2021 at 08:38:24 UTC, dangbinghoo wrote: but, where's these switch option documented? it seems it not appears in dmd --help or man dmd, or online document https://dlang.org/dmd-linux.html That's what he meant by "hidden" switch. I don't know why it isn't documented, b

Re: D compiler equivilent of "gcc -E" for debug/view template instantiation(generated) code?

2021-07-30 Thread dangbinghoo via Digitalmars-d-learn
On Friday, 30 July 2021 at 06:46:18 UTC, WebFreak001 wrote: On Friday, 30 July 2021 at 06:00:41 UTC, dangbinghoo wrote: Not sure if this is exactly what you want but there is a hidden switch in dmd called `-vcg-ast` that prints out all the templates instantiated. but, where's these switch

Re: D compiler equivilent of "gcc -E" for debug/view template instantiation(generated) code?

2021-07-30 Thread dangbinghoo via Digitalmars-d-learn
On Friday, 30 July 2021 at 06:46:18 UTC, WebFreak001 wrote: On Friday, 30 July 2021 at 06:00:41 UTC, dangbinghoo wrote: Not sure if this is exactly what you want but there is a hidden switch in dmd called `-vcg-ast` that prints out all the templates instantiated. On run.dlang.io you can use

Re: D compiler equivilent of "gcc -E" for debug/view template instantiation(generated) code?

2021-07-29 Thread WebFreak001 via Digitalmars-d-learn
On Friday, 30 July 2021 at 06:00:41 UTC, dangbinghoo wrote: hi, is there any D compiler option or other method to view the final template instantiation but not compiled (in asm or binary) code? if there's a way, it might be very usefull for newbies like me to learn and understand th

D compiler equivilent of "gcc -E" for debug/view template instantiation(generated) code?

2021-07-29 Thread dangbinghoo via Digitalmars-d-learn
hi, is there any D compiler option or other method to view the final template instantiation but not compiled (in asm or binary) code? if there's a way, it might be very usefull for newbies like me to learn and understand the the Meta programming of dlang. thanks! dbh

Re: Implicit Function Template Instantiation (IFTI) Question

2020-04-27 Thread jmh530 via Digitalmars-d-learn
On Monday, 27 April 2020 at 17:40:06 UTC, Steven Schveighoffer wrote: [snip] Thanks for that. Very detailed. In terms of a use case, we just added a center function to mir [1]. It can take an alias to a function. I wanted to add a check that the arity of the function was 1, but it turned out

Re: Implicit Function Template Instantiation (IFTI) Question

2020-04-27 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Apr 27, 2020 at 05:19:35PM +, jmh530 via Digitalmars-d-learn wrote: > When using a template with multiple functions within it, is it > possible to access the underlying functions directly? Yes, but only if the template is not eponymous. > Not sure I am missing anything, but what work

Re: Implicit Function Template Instantiation (IFTI) Question

2020-04-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/27/20 1:19 PM, jmh530 wrote: When using a template with multiple functions within it, is it possible to access the underlying functions directly? Not sure I am missing anything, but what works when the functions are named differently from the headline template doesn't work when the functio

Implicit Function Template Instantiation (IFTI) Question

2020-04-27 Thread jmh530 via Digitalmars-d-learn
When using a template with multiple functions within it, is it possible to access the underlying functions directly? Not sure I am missing anything, but what works when the functions are named differently from the headline template doesn't work when the functions are named the same. import st

Re: template instantiation problems

2020-01-14 Thread Boris Carvajal via Digitalmars-d-learn
On Friday, 10 January 2020 at 18:31:59 UTC, ag0aep6g wrote: import m1 = foo.baz; import m2 = foo; alias p = __traits(parent, m1); pragma(msg, m1.stringof); /* "module baz", ok */ pragma(msg, m2.stringof); /* "module foo", ok */ pragma(msg, p.stringof); /* "package foo", ok */ enum e(alias

Re: template instantiation problems

2020-01-10 Thread ag0aep6g via Digitalmars-d-learn
On 10.01.20 18:27, berni44 wrote: This clearly shows, that packageName is only instatiated once at top level although mod0 and mod1 are two different things (at least their stringof produces different results) and therefore should be instantiated twice. Now I don't know if this is a bug in DM

template instantiation problems

2020-01-10 Thread berni44 via Digitalmars-d-learn
I'm trying to understand issue 17441 [1]. I reduced it (including Phobos) to the following (and added some message to point out the problem): test.d: --- alias parentOf(alias sym) = __traits(parent, sym); template packageName(alias T) { pragma(msg, "IN: ", T.stringof); static if (__tra

Re: Should I stop being interested in D language if I don't like to see template instantiation in my code?

2019-11-14 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 14 November 2019 at 09:30:23 UTC, user9876 wrote: A good thing is that in many cases the template instance parameters can be deduced from the arguments used: --- import std; void main() { assert(max(0,1) == 1); // same as assert(max!(int,int)(0,1) == 1); } --- This featur

Re: Should I stop being interested in D language if I don't like to see template instantiation in my code?

2019-11-14 Thread user9876 via Digitalmars-d-learn
On Wednesday, 13 November 2019 at 14:01:13 UTC, BoQsc wrote: I don't like to see exclamation marks in my code in as weird syntax as these ones: to!ushort(args[1]) s.formattedRead!"%s!%s:%s"(a, b, c); I'm not sure why, but template instantiation syntax is prevalent

Re: Should I stop being interested in D language if I don't like to see template instantiation in my code?

2019-11-13 Thread berni44 via Digitalmars-d-learn
On Wednesday, 13 November 2019 at 14:23:40 UTC, mipri wrote: 3. it's very clear what's a compile-time vs. a runtime parameter to the template. At least, if one understands the difference. I remember that I was not aware of this, when I started learning D and was a lot confused by the use of t

Re: Should I stop being interested in D language if I don't like to see template instantiation in my code?

2019-11-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/13/19 9:01 AM, BoQsc wrote: I don't like to see exclamation marks in my code in as weird syntax as these ones: to!ushort(args[1]) s.formattedRead!"%s!%s:%s"(a, b, c); I'm not sure why, but template instantiation syntax is prevalent in the documentation examples of

Re: Should I stop being interested in D language if I don't like to see template instantiation in my code?

2019-11-13 Thread Dukc via Digitalmars-d-learn
On Wednesday, 13 November 2019 at 14:59:57 UTC, Dukc wrote: 4: Templates. Same code size bloat as with options 1 and 3, Meant binary size bloat

Re: Should I stop being interested in D language if I don't like to see template instantiation in my code?

2019-11-13 Thread Dukc via Digitalmars-d-learn
On Wednesday, 13 November 2019 at 14:01:13 UTC, BoQsc wrote: I don't like to see exclamation marks in my code in as weird syntax as these ones: to!ushort(args[1]) s.formattedRead!"%s!%s:%s"(a, b, c); No pressure to use templates. D is designed to be multi-paradigm, and in many was combines th

Re: Should I stop being interested in D language if I don't like to see template instantiation in my code?

2019-11-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 13, 2019 7:01:13 AM MST BoQsc via Digitalmars-d-learn wrote: > I don't like to see exclamation marks in my code in as weird > > syntax as these ones: > > to!ushort(args[1]) > > s.formattedRead!"%s!%s:%s"(a, b, c); > > I'm not

Re: Should I stop being interested in D language if I don't like to see template instantiation in my code?

2019-11-13 Thread mipri via Digitalmars-d-learn
ly* doing some work at compile-time here, instead of at runtime like other languages force me to") than an alert ("something weird is happening!") though. 3. it's very clear what's a compile-time vs. a runtime parameter to the template. I'm not sure why, but template inst

Should I stop being interested in D language if I don't like to see template instantiation in my code?

2019-11-13 Thread BoQsc via Digitalmars-d-learn
I don't like to see exclamation marks in my code in as weird syntax as these ones: to!ushort(args[1]) s.formattedRead!"%s!%s:%s"(a, b, c); I'm not sure why, but template instantiation syntax is prevalent in the documentation examples of d lang libraries. It almost se

Re: Shared, ref, arrays, and reserve template instantiation

2018-09-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, September 12, 2018 9:42:19 PM MDT James Blachly via Digitalmars-d-learn wrote: > Neia is right that I tried to cast as in the second case ( but > without UFCS -- reserve( cast(int[]), N); ). As an aside, what > is going on behind the scenes with the compiler when casting away > a pr

Re: Shared, ref, arrays, and reserve template instantiation

2018-09-12 Thread James Blachly via Digitalmars-d-learn
Great -- Thank you both. I previously found Unqual, but it looks like that needs template support so wasn't feasible, hence my question. Neia is right that I tried to cast as in the second case ( but without UFCS -- reserve( cast(int[]), N); ). As an aside, what is going on behind the scene

Re: Shared, ref, arrays, and reserve template instantiation

2018-09-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, September 12, 2018 5:41:16 PM MDT James Blachly via Digitalmars-d-learn wrote: > When I add the "shared" attribute to an array, I am no longer > able to call reserve because the template won't instantiate: > > Error: template object.reserve cannot deduce function from > argument type

Re: Shared, ref, arrays, and reserve template instantiation

2018-09-12 Thread Neia Neutuladh via Digitalmars-d-learn
On Wednesday, 12 September 2018 at 23:41:16 UTC, James Blachly wrote: When I add the "shared" attribute to an array, I am no longer able to call reserve because the template won't instantiate: Error: template object.reserve cannot deduce function from argument types !()(shared(int[]), int), ca

Shared, ref, arrays, and reserve template instantiation

2018-09-12 Thread James Blachly via Digitalmars-d-learn
When I add the "shared" attribute to an array, I am no longer able to call reserve because the template won't instantiate: Error: template object.reserve cannot deduce function from argument types !()(shared(int[]), int), candidates are: /dlang/dmd/linux/bin64/../../src/druntime/import/object.d

Re: Is there a way to get the address of the function that would be used in Implicit Function Template Instantiation?

2018-06-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, June 27, 2018 22:59:03 Nathan S. via Digitalmars-d-learn wrote: > On Wednesday, 27 June 2018 at 22:39:26 UTC, Jonathan M Davis > > wrote: > > You could explicitly instantiate the function template and then > > take its address. > > Explicitly instantiating the template can result in

Re: Is there a way to get the address of the function that would be used in Implicit Function Template Instantiation?

2018-06-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/27/18 6:34 PM, Nathan S. wrote: Let's say there's a function template `doImpl` and `doImpl(x)` compiles thanks to IFTI. Is there any way to get the address of the function that would be called in `doImpl(x)`? It's a good question! You may be able to use TemplateOf, TemplateArgsOf, and In

Re: Is there a way to get the address of the function that would be used in Implicit Function Template Instantiation?

2018-06-27 Thread Nathan S. via Digitalmars-d-learn
On Wednesday, 27 June 2018 at 22:39:26 UTC, Jonathan M Davis wrote: You could explicitly instantiate the function template and then take its address. Explicitly instantiating the template can result in a function that may be behaviorally identical but have a different address. https://run.dl

Re: Is there a way to get the address of the function that would be used in Implicit Function Template Instantiation?

2018-06-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, June 27, 2018 22:34:46 Nathan S. via Digitalmars-d-learn wrote: > Let's say there's a function template `doImpl` and `doImpl(x)` > compiles thanks to IFTI. Is there any way to get the address of > the function that would be called in `doImpl(x)`? You could explicitly instantiate the

Is there a way to get the address of the function that would be used in Implicit Function Template Instantiation?

2018-06-27 Thread Nathan S. via Digitalmars-d-learn
Let's say there's a function template `doImpl` and `doImpl(x)` compiles thanks to IFTI. Is there any way to get the address of the function that would be called in `doImpl(x)`?

Re: Template instantiation fails on Linux, succeeds on Windows

2018-05-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/17/18 7:33 PM, Bastiaan Veelo wrote: On Thursday, 17 May 2018 at 23:18:32 UTC, Basile B. wrote: On Thursday, 17 May 2018 at 22:07:46 UTC, Bastiaan Veelo wrote: Hi! The code in [1] compiles and runs flawlessly on Windows, but not on Linux (neither run.dlang nor Travis docker image). Any i

Re: Template instantiation fails on Linux, succeeds on Windows

2018-05-17 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 17 May 2018 at 23:18:32 UTC, Basile B. wrote: On Thursday, 17 May 2018 at 22:07:46 UTC, Bastiaan Veelo wrote: Hi! The code in [1] compiles and runs flawlessly on Windows, but not on Linux (neither run.dlang nor Travis docker image). Any idea what can be done? Hello. Yes, add `i

Re: Template instantiation fails on Linux, succeeds on Windows

2018-05-17 Thread Basile B. via Digitalmars-d-learn
On Thursday, 17 May 2018 at 22:07:46 UTC, Bastiaan Veelo wrote: Hi! The code in [1] compiles and runs flawlessly on Windows, but not on Linux (neither run.dlang nor Travis docker image). Any idea what can be done? Hello. Yes, add `import core.stdc.stdarg;` in your module and it works. I do

Template instantiation fails on Linux, succeeds on Windows

2018-05-17 Thread Bastiaan Veelo via Digitalmars-d-learn
Hi! The code in [1] compiles and runs flawlessly on Windows, but not on Linux (neither run.dlang nor Travis docker image). Any idea what can be done? errors: Error: undefined identifier __va_list_tag onlineapp.d(282): Error: template instance `onlineapp.SetFactory!byte` error instantiating

Re: Error in template instantiation from D-Cookbook example

2018-02-09 Thread ShadoLight via Digitalmars-d-learn
On Friday, 9 February 2018 at 21:39:22 UTC, Adam D. Ruppe wrote: On Friday, 9 February 2018 at 21:31:29 UTC, ShadoLight wrote: [1] https://run.dlang.io/is/dyElXg There's missing quotes in there: Line 14: code ~= "push(call!"~piece~"(pop(), pop()));\n"; Should be: code ~= "push(call!\""~piec

Re: Error in template instantiation from D-Cookbook example

2018-02-09 Thread Meta via Digitalmars-d-learn
On Friday, 9 February 2018 at 21:31:29 UTC, ShadoLight wrote: writeln(parse(code)); // to aid with debugging writeln(convertToD(parse(code))); // debugging aid ..to.. writeln(parse(code)[]); // to aid with debugging writeln(convertToD(parse(

Re: Error in template instantiation from D-Cookbook example

2018-02-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 9 February 2018 at 21:31:29 UTC, ShadoLight wrote: [1] https://run.dlang.io/is/dyElXg There's missing quotes in there: Line 14: code ~= "push(call!"~piece~"(pop(), pop()));\n"; Should be: code ~= "push(call!\""~piece~"\"(pop(), pop()));\n"; That might have been an error in the o

Error in template instantiation from D-Cookbook example

2018-02-09 Thread ShadoLight via Digitalmars-d-learn
Hi, Trying to improve my CT-fu, I looked at a DSL example (chapter 9) in Adam's D-Cookbook. Although I am sure Adam's original examples would have worked, there were some errors in the example code in the book. The example also contains some code to allow you to test the functions at RT, wh

Re: Weird template instantiation problem

2017-06-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/12/17 11:31 AM, Arafel wrote: As you can see, the only change is the type the function returns, but I don't see how it should make any difference. Also, changing from "enum" to "static immutable", or even removing the "enum" and directly embedding the function literal doesn't seem to make

Re: Weird template instantiation problem

2017-06-13 Thread Arafel via Digitalmars-d-learn
Well, I had kind of found a workaround (changing the return type to return the element and not the index) which I didn't like too much (what if there are duplicates?). Now that I've found a "proper" workaround well, I'm still interested in knowing the reason, if possible, or if it's a bug.

Re: Weird template instantiation problem

2017-06-12 Thread ketmar via Digitalmars-d-learn
Arafel wrote: I actually found a workaround for the original issue: yeah, sorry for not proposing a workaround: i thought that you already did it, and now you're just interested why the original code doesn't work. ;-) i think that this is a bug (or, rather, unimplemented feature).

Re: Weird template instantiation problem

2017-06-12 Thread Arafel via Digitalmars-d-learn
On Monday, 12 June 2017 at 19:23:10 UTC, ketmar wrote: p.s.: while i understand the technical reason for second error message, it is still random and confusing. I think the reason for the typeof problem is that it works with expressions, not with types (so, typeof (int) is also not valid), an

Re: Weird template instantiation problem

2017-06-12 Thread ketmar via Digitalmars-d-learn
p.s.: while i understand the technical reason for second error message, it is still random and confusing.

Re: Weird template instantiation problem

2017-06-12 Thread ketmar via Digitalmars-d-learn
more funny compiler messages: alias xx = size_t function (int[]); struct S1(T, typeof(xx) X) {} void main() { S1!(int, defaultChooser!int) s; } Error: type uint function(int[]) is not an expression but: struct S2(T, typeof(defaultChooser!T) cho

Re: Weird template instantiation problem

2017-06-12 Thread Arafel via Digitalmars-d-learn
On 06/12/2017 05:31 PM, Arafel wrote: Hi, I've found a strange problem, and I'm not sure if it's a bug. To give a bit of background, I'm implementing a multi-threaded producer-consumer where the next work item to be picked depends not only on the "waiting queue", but also on what else is bein

Weird template instantiation problem

2017-06-12 Thread Arafel via Digitalmars-d-learn
Hi, I've found a strange problem, and I'm not sure if it's a bug. To give a bit of background, I'm implementing a multi-threaded producer-consumer where the next work item to be picked depends not only on the "waiting queue", but also on what else is being run (and potentially where) at the s

Re: Recursive template instantiation

2017-03-13 Thread ag0aep6g via Digitalmars-d-learn
On 03/13/2017 11:58 PM, Stefan Koch wrote: On Monday, 13 March 2017 at 22:05:24 UTC, Jack Applegame wrote: Is this a bug? No it's not struct C { B!C; } is an error. Howto compute C ? <--\ let's check the members; | The member needs a template. | Howto compute the template

Re: Recursive template instantiation

2017-03-13 Thread ag0aep6g via Digitalmars-d-learn
On 03/14/2017 12:02 AM, Stefan Koch wrote: On Monday, 13 March 2017 at 22:59:36 UTC, ag0aep6g wrote: [...] struct A(T) { void m() { char[T.sizeof] data; } } /* ... rest as above ... */ I don't see how the destructor makes a difference. Soo, bug? Try to use m. Work

Re: Recursive template instantiation

2017-03-13 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 13 March 2017 at 22:59:36 UTC, ag0aep6g wrote: On 03/13/2017 03:26 PM, Jack Applegame wrote: I'm pretty sure that this code should compile (https://dpaste.dzfl.pl/cf1e1ee6ef4b): struct A(T) { ~this() { char[T.sizeof] data; } } struct B(T) { A!T foo; } struct C {

Re: Recursive template instantiation

2017-03-13 Thread ag0aep6g via Digitalmars-d-learn
On 03/13/2017 03:26 PM, Jack Applegame wrote: I'm pretty sure that this code should compile (https://dpaste.dzfl.pl/cf1e1ee6ef4b): struct A(T) { ~this() { char[T.sizeof] data; } } struct B(T) { A!T foo; } struct C { B!C bar; } void main() { C c; } But it doesn't:

Re: Recursive template instantiation

2017-03-13 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 13 March 2017 at 22:05:24 UTC, Jack Applegame wrote: Is this a bug? No it's not struct C { B!C; } is an error. Howto compute C ? <--\ let's check the members; | The member needs a template. | Howto compute the template ? | let's compute the parameters. | What

Re: Recursive template instantiation

2017-03-13 Thread Jack Applegame via Digitalmars-d-learn
Is this a bug?

Recursive template instantiation

2017-03-13 Thread Jack Applegame via Digitalmars-d-learn
I'm pretty sure that this code should compile (https://dpaste.dzfl.pl/cf1e1ee6ef4b): struct A(T) { ~this() { char[T.sizeof] data; } } struct B(T) { A!T foo; } struct C { B!C bar; } void main() { C c; } But it doesn't: /d300/f416.d(3): Error: struct f416.C no size

Re: Getting the template name of a template instantiation

2016-06-27 Thread Nordlöw via Digitalmars-d-learn
On Monday, 27 June 2016 at 17:17:19 UTC, John wrote: import std.traits; __traits(identifier, TemplateOf!(S!int)); Scratch that, this is what you want: import std.traits; static assert(__traits(isSame, TemplateOf!(S!int), S)); I believe this is what import std.traits : isInstanceOf; is

Re: Getting the template name of a template instantiation

2016-06-27 Thread John via Digitalmars-d-learn
On Monday, 27 June 2016 at 17:14:23 UTC, John wrote: On Monday, 27 June 2016 at 16:40:09 UTC, Nordlöw wrote: If I have a template parameter E = S!int where struct S(T) { S x; } how can I extract the template name part `S` from E`? Something like: static assert(is(templateName!(

Re: Getting the template name of a template instantiation

2016-06-27 Thread Ali Çehreli via Digitalmars-d-learn
On 06/27/2016 09:54 AM, Lodovico Giaretta wrote: On Monday, 27 June 2016 at 16:40:09 UTC, Nordlöw wrote: If I have a template parameter E = S!int where struct S(T) { S x; } how can I extract the template name part `S` from E`? Something like: static assert(is(templateName!(S!in

Re: Getting the template name of a template instantiation

2016-06-27 Thread John via Digitalmars-d-learn
On Monday, 27 June 2016 at 16:40:09 UTC, Nordlöw wrote: If I have a template parameter E = S!int where struct S(T) { S x; } how can I extract the template name part `S` from E`? Something like: static assert(is(templateName!(S!int) == S)); Is this already in Phobos somewhere?

Re: Getting the template name of a template instantiation

2016-06-27 Thread Lodovico Giaretta via Digitalmars-d-learn
On Monday, 27 June 2016 at 16:40:09 UTC, Nordlöw wrote: If I have a template parameter E = S!int where struct S(T) { S x; } how can I extract the template name part `S` from E`? Something like: static assert(is(templateName!(S!int) == S)); Is this already in Phobos somewhere?

Getting the template name of a template instantiation

2016-06-27 Thread Nordlöw via Digitalmars-d-learn
If I have a template parameter E = S!int where struct S(T) { S x; } how can I extract the template name part `S` from E`? Something like: static assert(is(templateName!(S!int) == S)); Is this already in Phobos somewhere?

Re: template instantiation

2016-05-20 Thread tsbockman via Digitalmars-d-learn
On Thursday, 19 May 2016 at 20:14:48 UTC, vit wrote: Is this a bug? Yes. I've filed a report: https://issues.dlang.org/show_bug.cgi?id=16050

template instantiation

2016-05-19 Thread vit via Digitalmars-d-learn
///Hello, i'm trying to implement d compiler and i've problems with some template corner cases. class Type{} class Foo(T : const T){ alias X = T; } alias Bar(T : Foo!Ts, Ts...) = Ts[0]; pragma(msg, "Foo1: ", Foo!(immutable Type).X);//Foo1: Type pragma(msg, "Foo2: ", F

Re: __traits(compiles) and template instantiation

2016-04-08 Thread jmh530 via Digitalmars-d-learn
It looks like the bug has already been reported. There are a few associated with __traits(compiles), but this one seems most relevant: https://issues.dlang.org/show_bug.cgi?id=3448 It also suggests that this is relevant: https://issues.dlang.org/show_bug.cgi?id=965

Re: __traits(compiles) and template instantiation

2016-04-07 Thread jkpl via Digitalmars-d-learn
On Thursday, 7 April 2016 at 21:36:37 UTC, Alex Parrill wrote: On Thursday, 7 April 2016 at 20:31:12 UTC, jmh530 wrote: I've been playing around with __traits and I find myself confused on one aspect. In the code below, I was testing whether some templates would compile given types. For the mos

Re: __traits(compiles) and template instantiation

2016-04-07 Thread Alex Parrill via Digitalmars-d-learn
On Thursday, 7 April 2016 at 20:31:12 UTC, jmh530 wrote: I've been playing around with __traits and I find myself confused on one aspect. In the code below, I was testing whether some templates would compile given types. For the most part it works as I would expect. I think I get why the thir

__traits(compiles) and template instantiation

2016-04-07 Thread jmh530 via Digitalmars-d-learn
I've been playing around with __traits and I find myself confused on one aspect. In the code below, I was testing whether some templates would compile given types. For the most part it works as I would expect. I think I get why the third one works with foo!(int). My guess is that it assumed t

Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-30 Thread Adrian Matoga via Digitalmars-d-learn
On Saturday, 30 January 2016 at 00:16:21 UTC, Ali Çehreli wrote: > https://issues.dlang.org/show_bug.cgi?id=15623 As I noted on the bug report, they are work when moved from module scope to inside a function (e.g. main()). At least there's that workaround... Ali Thanks a lot! Now I can con

Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-30 Thread Adrian Matoga via Digitalmars-d-learn
On Friday, 29 January 2016 at 23:44:56 UTC, Basile B. wrote: Haven't you seen my answer about constraint ? If you put a constraint on your function template then invalid instantiations are rejected. I mean... this language feature is not just ornamental... What do you think constraints are u

Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-29 Thread Ali Çehreli via Digitalmars-d-learn
On 01/29/2016 09:01 AM, Adrian Matoga wrote: > Oh, there's more: > // this should fail: > static assert(is(CallsFoo!NoFoo)); > // this should fail too: > static assert(is(typeof({ alias Baz = CallsFoo!NoFoo; return Baz.init; > }(; > // and this: > static assert(__traits(compiles, { alias Baz

Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-29 Thread Steven Schveighoffer via Digitalmars-d-learn
^ A constraint should not be necessary here. Constraints are useful when you have multiple templates that may match (without specializations), or you want to affect the way the compiler reports errors. Iff a template instantiation T compiles, then is(T) should evaluate to true. At least, that

  1   2   >