std.container.slist: Fix -dip1000 compilable issues#6387
std.container.slist: Fix -dip1000 compilable issues#6387carblue wants to merge 2 commits intodlang:masterfrom carblue:std_container_slist_1
Conversation
|
Thanks for your pull request and interest in making D better, @carblue! 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 fetch digger
dub run digger -- build "master + phobos#6387" |
| { | ||
| auto newNode = new Node(null, item); | ||
| static if (isSomeString!T) | ||
| auto newNode = new Node(null, item.dup); |
There was a problem hiding this comment.
Didn't we agree that this is bad because we duplicate memory without the user explicitly agreeing too.
Why not version(DIP1000) else out the test for now? And/or report the DMD error I reduced here: #6295 (comment)
There was a problem hiding this comment.
Also, wouldn't special-casing strings this way break all other reference types anyway?
| { | ||
| auto newNode = new Node(null, item); | ||
| static if (isSomeString!T) | ||
| auto newNode = new Node(null, item.dup); |
There was a problem hiding this comment.
Also, wouldn't special-casing strings this way break all other reference types anyway?
| Complexity: $(BIGOH m), where $(D m) is the length of $(D stuff) | ||
| */ | ||
| size_t insertFront(Stuff)(Stuff stuff) | ||
| size_t insertFront(Stuff)(scope Stuff stuff) |
There was a problem hiding this comment.
Inserting an element in a container is really escaping it, so this function can't accept scope arguments by design, unless it always stores a copy of them.
A new attempt since #6295
https://github.com/dlang/phobos/blob/master/dip1000.mak with
aa[std.container.slist]=-dip1000
Errors when running: make -f posix.mak std/container/slist.test
...
Changing to:
size_t insertFront(Stuff)(scope Stuff stuff)
if (isInputRange!Stuff && isImplicitlyConvertible!(ElementType!Stuff, T))
compiles everything except: auto sl = SList!string(["a", "b", "d"]);
Thus I'm going to try with a dedicated constructor (or ?) for the string types, probably including dup-ing consructor arguments. We'll see.