Tuple's toString made useful#3594
Conversation
std/typecons.d
Outdated
There was a problem hiding this comment.
Just do is(Type == shared)?
There was a problem hiding this comment.
Just do
is(Type == shared)?
I had that in mind, too, but I've never dealt with shared types. Indeed, I believe there is a difference that is not obvious, just because those who wrote that should have had this in mind—but didn't do that. Therefore I left it like that.
In the next pull request, it'll be the simple one. Let's see what others think about it.
|
I'm new to this. @JakobOvrum can you (or someone else) explain me why the auto-tester rejects my code? I'm pretty sure that |
|
@Bolpat Tests that infrequently fail can make their way into the auto tester. It's annoying, because it seems like your change is being rejected, but it's just complete dumb luck. However, your pull is failing pretty much everything. That doesn't necessarily mean the code you have written is wrong, it may be that it uncovered a latent bug. If you can run unit tests locally and get a failure, it may help. |
|
@schveiguy Thanks! I've tried like this: Create a new file with only main, only containing the unit test. It worked perfectly. Then I tried |
That is an unrelated soft failure. Ignore it. The real failure is somewhere else in the same log. For example now I see: Maybe this? |
|
I now used Phobos' unittest.d. It works with the submitted unit test, and fails on a altered one supposed to fail. |
std/typecons.d
Outdated
There was a problem hiding this comment.
The brackets around fmt.spec shouldn't be needed; char should be able to be concatenated with slices of char freely. It is an unnecessary GC allocation.
|
I'm sorry for this hanging so long, this is a really cool feature that we should get merged and espouse in the changelog. Does anyone know what's going on with the unit tester? |
|
There are some strange things going on here. It seems |
|
@Bolpat, I filed a pull request to your PR fixing the segfault. |
|
@JakobOvrum Thanks. |
std/typecons.d
Outdated
There was a problem hiding this comment.
This line looks redundant (and there's some strange whitespace in the line above)
There was a problem hiding this comment.
It is redundant. I've deleted it, but it's not worth pushing and letting the auto-tester do it's work all again.
The real question is: Do we really want to have assertThrown in the unit test?
There was a problem hiding this comment.
I think it's definitely good to test, but I'm not sure whether it's worth including in the documented unit test.
However, Tuple's unit tests might be or become a performance issue; since they are templated, there are as many copies of the unittest as there are unique template instantiations. In std.container we reverted to using DDoc example sections and moving the unittests outside the template because of this issue, despite the source code duplication it causes. That sort of change is beyond the scope of this PR, but I thought I might mention it anyway.
There was a problem hiding this comment.
It's good to be mentioned. If it really is a performance issue, it has to be done. It shouldn't be a big thing, or was it in std.container?
|
Otherwise LGTM. Please squash the intermediate commits that deal with testing or commenting of code (and the merge commit). |
|
I have a question about line 784, the alternative function declaration. Usually the character type is one of |
|
The commented out signature should work just fine: void toString(DG, Char)(scope DG sink, std.format.FormatSpec!Char fmt = "%s") const |
|
No, it definitely doesn't. Not like this and the two thousand other ways I tried. Is it even worth? |
|
It works for me when I remove the full qualification of edit: The default argument doesn't make any sense for |
|
When I wrote the full qualification, I did it because it was necessary. So you've imported |
|
Yes, std.format needs to be imported. You can put the import declaration inside the
And what exactly do you expect it to do? |
That looks so odd to me (from my C++ perspective) so I indeed didn't try.
I thought the constructor would parse the input. It just passes it to |
|
@Bolpat, if the generalisation of edit: Oh, you've fixed it, nevermind. |
std/typecons.d
Outdated
There was a problem hiding this comment.
This needs at least an empty documentation comment (e.g. ///) for the documentation for the nested symbols to show up.
|
There are some things I'm suspicious about. In
It seems |
|
Another question, now that Tuples have first-class |
|
The attributes should be added to the unittest, not As for templatizing the chunk type or changing the textual representation of "%s" for |
|
Some Results: The unittest is |
|
LGTM. Please clean up the commits so we can merge. |
|
What do you exactly mean with cleaning up? Squash all commits? |
|
@Bolpat Yes, this should be one commit. |
|
What's going on here? |
|
Oh boy. I'm assume you tried to rebase on This will bring you into an interactive session in your preferred command line text editor. Use the on screen instructions to delete the commits that aren't yours and squish the ones that are yours ( |
|
If that worked, you'll have to |
# The first commit's message is: # This is a combination of 10 commits. # The first commit's message is: # This is a combination of 2 commits. # The first commit's message is: # This is a combination of 5 commits. # The first commit's message is: Tuple's toString made useful. http://forum.dlang.org/thread/srofuqyrdzphgzylbwds@forum.dlang.org Format Tuple's fields with format in %(%|%), similar to arrays, or, without %|, each filed specifically. Doesn't break any existing code as %s qualifier's behavior is not modified The overload without parameters is intentionally left as a template, as it appears to reveal some bugs in std.format for certain types. Remove the template parameter list to reproduce. # This is the 2nd commit message: dynamically load libcurl - avoids issues with versioned symbols on different platforms - lazy loading/initialization of curl library - fix Issue 13324 - try to load curl from the exe itself before loading a shared library thus allowing to link against a different or a static curl library # This is the 3rd commit message: fix Issue 14949 - Non-descriptive "Enforcement failed" when attempting to write to closed file # This is the 4th commit message: remove data argument from options - it's unlikely that the non-usage of OPTIONS body changes anytime soon # This is the 5th commit message: Allow Variant.visit to support const types. Assuming that Foo.depth and Bar.depth are both const (e.g. both are just int members), the following should compile: ----- int depth(in FooBar fb) { return fb.visit!((Foo foo) => foo.depth, (Bar bar) => bar.depth); } ----- However, it was failing with: std/variant.d(2246): Error: cannot implicitly convert expression (variant.peek()) of type const(Foo)* to Foo* std/variant.d(2246): Error: cannot implicitly convert expression (variant.peek()) of type const(Bar)* to Bar* This patch changes an explicit `T*` declaration to an `auto` declaration so const types can be visited. # This is the 2nd commit message: fix docs for HTTP only requests # This is the 2nd commit message: Fix broken hyperlinks to std.algorithm submodules. # This is the 3rd commit message: Leading rows in Container Primitives table should span all columns. Depends on: dlang/dlang.org#1071 # This is the 4th commit message: Add missing references to std.digest.hmac to fix doc generation # This is the 5th commit message: Added Andrei's Getting Started Guide # This is the 6th commit message: Fix Issue 14884 # This is the 7th commit message: Ignore .lst files # This is the 8th commit message: Add sameHead/sameTail to function list in docs. # This is the 9th commit message: std.traits.hasMember: just forward to __traits(hasMember, ...) This way opDispatch'ed members are recognized. Fixes issue 14605 - RefAppender fails isOutputRange. # This is the 10th commit message: Ddoc: add missing parenthesis # This is the 2nd commit message: Added /// # This is the 3rd commit message: Added attributes; clearify Documentation
|
I'm making things worse because I'm not really knowing what to do. It prompts me with |
|
Well, without really being there or knowing exactly what you did, I can't troubleshoot this. Does anyone else have any ideas. Also, I was afraid this might happen, so I made a copy of your changes before you tried rebasing. |
|
@JackStouffer Thank you very, very much. I gave you and @JakobOvrum write permissions. So you can do what you think is right. That's much better than delegating me. |
|
I don't have the time to fix this myself. Here is the backup I made http://dpaste.dzfl.pl/4c8ae5692fca I would suggest opening a new PR with the above code. Just make a new branch and delete this one. |
|
The new pull request is here. In the files I've only modified some bad English in the documentation. |
From http://forum.dlang.org/thread/srofuqyrdzphgzylbwds@forum.dlang.org
With this, you can easily format a Tuple from its content, similar how to do with an array.
The
toString(delegate, FormatSpec)function takes the formats%(nested%)and%(nested%|separator%)a bit different: The second one treats the Tuple as it was an array. The first one applies the nested format to the expanded fields, likeformat(nested, tup.expand)did.With this, the question http://forum.dlang.org/post/ntqawkupddjcijwtwovp@forum.dlang.org gets a trivial answer: Use
"%(%(%s%| %)\n%)"insted of"%(%(%s %)\n%)".It can be expected not to break any existing code.