-
-
Notifications
You must be signed in to change notification settings - Fork 609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid unnecessary template #16982
base: master
Are you sure you want to change the base?
Avoid unnecessary template #16982
Conversation
Thanks for your pull request and interest in making D better, @ryuukk! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#16982" |
Perhaps the right approach is to update the format function in edit: looks like dmd just validates the strings it passes to printf, lol |
|
You can't pass D slices to C-style variadic arguments. Even if you change that, the compiler is still being compiled with dmd version 2.079, so dmd's source can't rely on new features. The motivation for the helper function is:
What's the motivation for removing it in this PR? |
Reading The code that uses it is not complex, it doesn't justify it, you mention issues that are non existent in your PR The only way to prevent the future issues you mention is to make the function understand what a D string is, not to tell people to instead rely on this cryptic code |
I don't think a length, ptr pair is a ton of complexity. Perhaps
There's refactoring PRs converting C strings to D strings all the time. The idea is that it can be used for future PRs as well, not just the one PR that introduced it.
I want to, believe me, but for the time being we're stuck with printf and C variadics. I don't think this is worth discussing at length, perhaps @RazvanN7 and @thewilsonator can weigh in on whether it is too obfuscating, and if it is, we can merge this and I'll stop refactoring printf calls like this. |
/// | ||
unittest | ||
{ | ||
import core.stdc.stdio: snprintf; | ||
char[6] buf = '.'; | ||
const(char)[] str = "cutoff"[0..4]; | ||
snprintf(buf.ptr, buf.length, "%.*s", str.fTuple.expand); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This entire unittest should be removed, without fTuple it's moot
@@ -20,24 +20,13 @@ inout(char)[] toDString (inout(char)* s) pure nothrow @nogc | |||
return s ? s[0 .. strlen(s)] : null; | |||
} | |||
|
|||
private struct FTuple(T...) | |||
{ | |||
T expand; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does alias expand this;
work here? if so we should use it and give FTuple
a less cryptic name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried, but they won't auto expand in C-style variadic argument lists
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps str.lengthPtr.expand
is clearer?
No description provided.