Skip to content

Issue 9136 - Add isNested trait for aggregates and functions #1362

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 1 commit into from Mar 5, 2013
Merged

Issue 9136 - Add isNested trait for aggregates and functions #1362

merged 1 commit into from Mar 5, 2013

Conversation

ghost
Copy link

@ghost ghost commented Dec 10, 2012

http://d.puremagic.com/issues/show_bug.cgi?id=9136

This adds a new trait: __traits(isNested, T), which is true for type T if it's a nested type which holds a context pointer (aggregate or function).

Current library workarounds require using .stringof tricks, which probably isn't very reliable. This pull simplifies implementation of Phobos Pull 948.

I'll add a documentation pull if & after this pull is merged.

@alexrp
Copy link
Member

alexrp commented Dec 10, 2012

Seems reasonable to me.

@ghost
Copy link
Author

ghost commented Dec 10, 2012

@9rnsr: If you find any gotchas -- it would be great to know so we can make this trait reliable from the get-go.

@9rnsr
Copy link
Contributor

9rnsr commented Dec 11, 2012

All test codes for __traits is in test/runnable/traits.d, so I recommend to collect into there.

@9rnsr
Copy link
Contributor

9rnsr commented Dec 11, 2012

LGTM.

@9rnsr
Copy link
Contributor

9rnsr commented Dec 11, 2012

@AndrejMitrovic: Indeed. For nested class type, checking isNested traits is fairly difficult.

@ghost
Copy link
Author

ghost commented Dec 11, 2012

All test codes for __traits is in test/runnable/traits.d, so I recommend to collect into there.

Thanks, I was wondering where to put the testcase. Will update soon.

@ghost
Copy link
Author

ghost commented Dec 29, 2012

Note: I've changed the implementation (sorry to reviewer Kenji). It was necessary to disallow invalid argument count, and invalid checks like e.g. __traits(isNested, 123).

@ghost
Copy link
Author

ghost commented Feb 27, 2013

I've rebased this again, after the tester is green we should try merging it.

@MartinNowak
Copy link
Member

LGTM, but I would prefer to see a merged spec update first.

@ghost
Copy link
Author

ghost commented Feb 27, 2013

I'll make the spec pull.

Also I'm going to add another test-case which was missed:

static class A { static class SC { } class NC { } }
static assert(!__traits(isNested, A));
static assert(!__traits(isNested, A.SC));
static assert(__traits(isNested, A.NC));

@MartinNowak
Copy link
Member

Also I'm going to add another test-case which was missed:

So this already works for classes, great.

MartinNowak added a commit that referenced this pull request Mar 5, 2013
Issue 9136 - Add isNested trait for aggregates and functions
@MartinNowak MartinNowak merged commit 051c8be into dlang:master Mar 5, 2013
@denis-sh
Copy link
Contributor

denis-sh commented Mar 6, 2013

Updated std.traits.{isNested,hasNested} implementation in dlang/phobos#948.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants