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
Fix Issue 11938 - Add std.traits.CompatibleUnqual #1881
Conversation
CompatibleUnqual is similar to Unqual, except it only removes qualifiers when the unqualified type is compatible with the original type, i.e. is(T : CompatibleUnqual!T) is always true.
I'm not sure |
I believe it is useful. Several uses of An example: this gives a compile error inside import std.algorithm, std.range;
void main()
{
const(int[]) xs;
const ys = inputRangeObject(xs);
map!(a => a)(ys);
}
Problem is here: |
So why you don't fix the existing range algorithm issues with package |
@9rnsr I have given it |
It will turn up in documentation so it should really be public and documented. You could prove its value with examples that fail with |
We could leave it as "documented but private": Eg, we document the behavior so users know what it means when they encounter it, yet still can't use it directly. We simply explain it is an "experimental" trait. I too have some doubts about making it public, but documenting it won't hurt either. Best of both worlds I say :) |
Documented private or package symbols are ignored by DDoc, so they won't show up in generated documentation. We can't expect users to have to dig in source code to figure out what a particular template constraint means. |
Agreed.
Groan. That's a bitch. Seems more like a limitation than a feature. How would one document things like "private virtual interface"? |
|
@9rnsr given the above discussion and the uses inside |
By the way, I'm pretty sure most of these algorithms don't actually need edit: Nevermind, I think |
All of range algorithm fixes (replacement from I am really afraid about that adding more and more trait templates for certain situations. I really hate unnecessary bloating "D standard library". |
I'd love to add unit tests, but the purpose of those changes is to avoid internal template errors by catching them in the constraint. I'm not aware of any way to test that. I do understand your concern with library bloat, but I'm also concerned about all the blatantly incorrect uses of |
That's a good point. The NVI idiom (which doesn't currently work) comes to mind. |
I'm not sure about having all these functions accepting const ranges, since the const can be stripped at the call site, using I mostly had this in mind for RoR kind of algorithms, where stripping the "internal" const at call site is much harder: The original bug report of: immutable words string[] ["hello", "there"];
words.join(" ").writeln(); //"Should" work with IFTI, but fails on "second level" immutable Anywhoo, I found another use case that By having Or more generally any type that models containing a |
There is still the DDoc issue (which I can live with), but otherwise, for me, this is a welcome change and seems good to go. Any one have anything else to add? BTW, couldn't the ddoc issue be solved with a |
I don't want this pulled if @9rnsr is not happy with it. It's not a pressing issue, and maybe there is a language change that could make it unnecessary. |
I'd call it |
ping |
I wonder if we should instead add a template flag for |
I'm not sure what to do here. Andrei and Kenji are not convinced this is good, and I wouldn't want something going in when key people are not on board. Some things are clear to me:
Ideally I'd like this to be solved in the language, then this diff (and all the brokenness in Phobos) goes away. Head const should always be stripped, but to do that we'll need to find a way to copy const(T) to T, which is currently impossible. |
So do I but this issue has been discussed for ages with no good solution found so far. It can take few ages longer :( I agree though that there is no point in spending more time on this if @andralex and @9rnsr both do not like it - probably this pushes the change into the DIP domain. |
I will close this until it is either supported by more fundamental justification (thinking DIP) or @andralex naturally changes his mind. |
CompatibleUnqual
is similar toUnqual
, except it only removes qualifiers when the unqualified type is compatible with the original type, i.e.is(T : CompatibleUnqual!T)
is always true.https://d.puremagic.com/issues/show_bug.cgi?id=11938
As mentioned in the bug, this is useful when writing range algorithms and you want to get a mutable version of a range (when possible).