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
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 %
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 ~=
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
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
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
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 ~