4 ms·
One thing i really miss from C's printf or Java's MessageFormat is the ability to change argument positions: Different languages can display the argument in di
by hyperman1 6y ago
One thing i really miss from C's printf or Java's MessageFormat is the ability to change argument positions: Different languages can display the argument in different orders, and can have the format string in a resource bundle.
It is of course very hard to have type safety when the format string is in a resource bundle
- dthul 6y agoThe position of arguments is actually not required to follow the format string. From the documentation: println!("{1} {} {0} {}", 1, 2); // => "2 1 1 2" But you are right, you cannot dynamically change the format string. If you need this facility, there is the runtime_fmt crate which will parse the format string at runtime instead of compile time. That of course means that it can fail at runtime if the format string does not match the arguments.
- flohofwoe 6y agoPOSIX printf() actually supports positional arguments: https://www.godbolt.org/z/xG15M5 https://www.godbolt.org/z/xG15M5 Both clang and gcc support this, but unfortunately not the Microsoft C compiler. PS: actually, it does, just not in the normal printf call: https://docs.microsoft.com/en-us/cpp/c-runtime-library/printf-p-positional-parameters?view=vs-2019 https://docs.microsoft.com/en-us/cpp/c-runtime-library/print...
- andralex 6y agoD also supports POSIX positional arguments: https://dlang.org/library/std/format/formatted_write.html https://dlang.org/library/std/format/formatted_write.html
- deleted 6y ago[deleted]