c42f / tinyformat

Minimal, type safe printf replacement library for C++
537 stars 75 forks source link

Template program to count the number of format specifiers and check if they match the arguments count #64

Closed evandrocoan closed 4 years ago

evandrocoan commented 4 years ago

When some formatting function as "Hi %s %s.", "Hi" is used, it will throw a run-time error. If I understand correctly, C++ templates are Turing Complete, so they can do any computation.

Then, if they can do any computation, why they cannot count how many times I used the format specifiers Hi %s %s in my string, and check if this is equal to the number of parameters "Hi" passed to the formatting function?

nigels-com commented 4 years ago

It might be possible, but it might not be "tiny".

c42f commented 4 years ago

This is a duplicate of issue #19. It's a good idea and I'd implement it if I could. But last time I tried it had some severe consequences in uglifying the syntax required to use format() — see the last paragraph of https://github.com/c42f/tinyformat/issues/19#issuecomment-58802527 for details.