Skip to content

Wrap struct #2945

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

Merged
merged 7 commits into from
Apr 1, 2016
Merged

Wrap struct #2945

merged 7 commits into from
Apr 1, 2016

Conversation

JesseKPhillips
Copy link
Contributor

This implements the ability to wrap a structure into a specified interface using std.typecons.wrap. Some notes:

Bug is not an issue in HEAD.
-During these changes I came across this bug: https://issues.dlang.org/show_bug.cgi?id=12993-

When the struct is unable to be unwrapped I have thrown a ConvException. I considered using Nullable but think I was hitting issue 12993; another option would be to allow the user to specify the unwrap type to be Nullable!T.

I have pulled some logic into the isConceptWith template, which is private for now but may be something we'd want to be public and renamed?

I also added a constraint to wrap which verifies that Targets are all interfaces, which required a private template isInterface to be added.

https://issues.dlang.org/show_bug.cgi?id=14098

@CyberShadow
Copy link
Member

When the struct is unable to be unwrapped I have thrown an UnwrapException that I created.

I think ConvException could be used here.


interface Refleshable
{
int reflesh();
}
// does not have structural conformance
static assert(!__traits(compiles, d1.wrap!Refleshable));
static assert(!__traits(compiles, h1.wrap!Refleshable));
// issue 12993 prevents uncommenting these asserts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand, a compiler bug blocks this PR from not causing regressions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bug is no longer reproduceable in HEAD, will look into testing with 2.067 release to close it out.

@JakobOvrum
Copy link
Member

Ping @JesseKPhillips

@JesseKPhillips
Copy link
Contributor Author

Apologies, I did not see this in email until today. Not that I'd do much before I moved. Thanks for the review, will look at updating.

@JesseKPhillips
Copy link
Contributor Author

I've made the suggested changes and included new documentation for unwrap.

@JesseKPhillips
Copy link
Contributor Author

@JakobOvrum could you remove the 'needs work' label since I've addressed the review comments.

@@ -3875,14 +3875,118 @@ unittest
}

/**
* Determines if the $(D Source) type satisfies all interface requirements of
* $(D Targets)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfinished sentence. Generally this needs to be fleshed into real documentation for acceptance.

@JesseKPhillips
Copy link
Contributor Author

@andralex I've updated the doc comment and template name to implementsInterface.

@@ -3869,15 +3869,119 @@ unittest
assert(i.instance() is j.instance());
}

/*
* Determines if the $(D Source) type satisfies all interface requirements of
* $(D Targets).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: you may use backquotes


Macros:

WIKI = Phobos/StdVariant
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copypasta

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be pushing a fix shortly.

@JesseKPhillips
Copy link
Contributor Author

Been busy, hope to have the docs updated this weekend.

}

/*
* Avoids opCast operator overloading.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the value of this. If someone defined a class and made it a point to override normal cast behavior, then they may have a good reason. Let them eat cake.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of the original wrap, I'm not making changes to this functionality especially with this case where I don't know what it would break.

@andralex
Copy link
Member

Generally this lgtm, I'm a bit unsure about the handling of qualifiers.

@JesseKPhillips
Copy link
Contributor Author

@andralex, I've updated the docs and commented on the items I do not wish to change at this point.

@JakobOvrum JakobOvrum mentioned this pull request Jan 10, 2016
@JackStouffer
Copy link
Member

The documentation for this needs some work, maybe even a complete redo. For example

If Source has structural conformance with the interface Targets, wrap creates internal wrapper class which inherits Targets and wrap src object, then return it.

What does "structural conformance" mean? I don't even know where to being with the rest of the sentence because I have no idea what it's trying to say.

Also, it needs examples.

@wilzbach
Copy link
Member

wilzbach commented Mar 8, 2016

Ping @JesseKPhillips - As far as I can by skimming through this thread, docs are the only blocking issue?

@JackStouffer
Copy link
Member

Ping @JesseKPhillips; just improve the docs and this will be ready to go.

@JakobOvrum
Copy link
Member

I agree that handling of qualifiers here is dubious - I'll have a stab at improving the documentation, and then possibly solving the qualifiers issue. Hopefully Jesse will have enough time to consider PRs even if he doesn't have enough time to work on this, which is completely understandable.

@JakobOvrum
Copy link
Member

Hm, Github doesn't seem to recognize my commit:

JakobOvrum/phobos@wrapStruct...JesseKPhillips:wrapStruct

Even though at a glance it looks to be structured correctly:

base: https://github.com/JakobOvrum/phobos/commits/wrapStruct
head: https://github.com/JesseKPhillips/phobos/commits/wrapStruct

Well, the commit is there in my branch if anyone wants to review it, or @JesseKPhillips merge it into this PR.

@JesseKPhillips
Copy link
Contributor Author

@JakobOvrum I've pushed up your changes to the docs.

@quickfur
Copy link
Member

Since this is now targeting std.experimental, and @andralex seems to be generally in favor of it, I'm inclined to merge this first and if there are problems followup PRs can be submitted.

@quickfur
Copy link
Member

ping @JakobOvrum
If the docs look OK, I think we should merge this. Let's keep things moving instead of waiting for perfection which may never come.

@JackStouffer
Copy link
Member

@quickfur Even if the docs are bad I think we can merge if it's going into stdx

@quickfur
Copy link
Member

If @JakobOvrum doesn't respond by tomorrow I'll merge it.

@quickfur
Copy link
Member

Auto-merge toggled on

@quickfur quickfur merged commit 7be36e3 into dlang:master Apr 1, 2016
@JesseKPhillips JesseKPhillips deleted the wrapStruct branch February 10, 2019 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants