Thread overview
Creating std.format.format warpper
May 01, 2021
novice2
May 01, 2021
Anonymouse
May 01, 2021
novice2
May 01, 2021

Hello.

Can please anybody help me create template format2 like std.format.format,
so it can access to format string (change it for example)
then instantiate std.format.format template in compile-time-checkable way
format!"%d %s"(arg1, arg2)
so compiler can check format string vs arguments count at least.

i.e. if i would write
format2!"%d %s"(arg1)
i should give comile time error

and next difficulties, i want format2 have extra parameter (say "prefix"), not passed to std.format.format

for example, format2 should prepent prefix to format string then instantiate std.format.format

any advices
thanks

May 01, 2021

On Saturday, 1 May 2021 at 09:10:09 UTC, novice2 wrote:

>

Hello.

Can please anybody help me create template format2 like std.format.format,
so it can access to format string (change it for example)
then instantiate std.format.format template in compile-time-checkable way

Since std.format.format already does this, just create templates that simply pass on their arguments to it and let it validate them. "Prefixing" the format pattern is trivially done (in a separate template) before deferring to format.

https://run.dlang.io/is/QsYCkq

If you're not familiar with templates and the difference between compile-time and runtime parameters, there are several good write-ups, such as the template chapter of Ali Çehreli's book (which is available online at http://ddili.org/ders/d.en/templates.html).

May 01, 2021

On Saturday, 1 May 2021 at 16:21:33 UTC, Anonymouse wrote:

>

https://run.dlang.io/is/QsYCkq
http://ddili.org/ders/d.en/templates.html).

thanks for your time!