Re: Template specialized functions creating runtime instructions?

2019-08-21 Thread Patrick Schluter via Digitalmars-d-learn
On Wednesday, 21 August 2019 at 00:11:23 UTC, ads wrote: On Wednesday, 21 August 2019 at 00:04:37 UTC, H. S. Teoh wrote: On Tue, Aug 20, 2019 at 11:48:04PM +, ads via Digitalmars-d-learn wrote: [...] 2) Deducing the string as you describe would require CTFE (compile-time function

Re: Template specialized functions creating runtime instructions?

2019-08-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, August 20, 2019 5:48:04 PM MDT ads via Digitalmars-d-learn wrote: > This piece of code creates a fizzbuzz string with template > parameters. > > auto fizzbuzz(uint N)() { > string accumulate; > return fizzbuzz!N(accumulate); > } > > auto fizzbuzz(uint N)(ref string result) if (N %

Re: Template specialized functions creating runtime instructions?

2019-08-20 Thread ag0aep6g via Digitalmars-d-learn
On 21.08.19 01:48, ads wrote: This piece of code creates a fizzbuzz string with template parameters. auto fizzbuzz(uint N)() { string accumulate; return fizzbuzz!N(accumulate); } auto fizzbuzz(uint N)(ref string result) if (N % 3 && N % 5) { import std.conv : to; result ~=

Re: Template specialized functions creating runtime instructions?

2019-08-20 Thread ads via Digitalmars-d-learn
On Wednesday, 21 August 2019 at 00:04:37 UTC, H. S. Teoh wrote: On Tue, Aug 20, 2019 at 11:48:04PM +, ads via Digitalmars-d-learn wrote: [...] 2) Deducing the string as you describe would require CTFE (compile-time function evaluation), which usually isn't done unless the result is

Re: Template specialized functions creating runtime instructions?

2019-08-20 Thread ads via Digitalmars-d-learn
On Tuesday, 20 August 2019 at 23:48:04 UTC, ads wrote: https://godbolt.org/z/hWENgc A somewhat similar translation in C++ also creates a lot of runtime instructions https://godbolt.org/z/psyUtq

Re: Template specialized functions creating runtime instructions?

2019-08-20 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 20, 2019 at 11:48:04PM +, ads via Digitalmars-d-learn wrote: [...] > In the generated assembly, it looks like it is creating a lot of > runtime instructions, contrary to my belief that templated codes are > purely compile-time. I was expecting that the compiler would deduce > the

Template specialized functions creating runtime instructions?

2019-08-20 Thread ads via Digitalmars-d-learn
This piece of code creates a fizzbuzz string with template parameters. auto fizzbuzz(uint N)() { string accumulate; return fizzbuzz!N(accumulate); } auto fizzbuzz(uint N)(ref string result) if (N % 3 && N % 5) { import std.conv : to; result ~= N.to!string ~