Skip to content

Conversation

Hackerpilot
Copy link
Contributor

This pull request adds the getSymbolsByUDA template. It is used for getting a(n) Arguments/TypeTuple from a symbol consisting of that symbol or parts of the symbol that have the specified UDA. This functionality is very important for compile-time reflection.

import std.typetuple : Filter, staticMap, TypeTuple;
import std.traits : hasMember;

static enum hasSpecificUDA(alias S) = hasUDA!(S, attribute);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why static?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nonsense like template instance I!(d) cannot use local 'd' as parameter to non-global template I(alias T)

@Hackerpilot Hackerpilot force-pushed the add-getSymbolsByUDA branch from 42d124e to b3c2d04 Compare June 18, 2015 21:10
@atilaneves
Copy link
Contributor

LGTM

@schuetzm
Copy link
Contributor

Maybe add a note that this is not recursive?

@Hackerpilot
Copy link
Contributor Author

Added.


// Finds both UDA attributes.
static assert(getSymbolsByUDA!(B, UDA).length == 2);
// Finds one `100` atribute.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo atribute

@Hackerpilot
Copy link
Contributor Author

Anything holding this up?

import std.typetuple : Filter, staticMap, TypeTuple;

static enum hasSpecificUDA(alias S) = hasUDA!(S, attribute);
static alias I(alias T) = T;
Copy link
Member

Choose a reason for hiding this comment

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

I think std.traits.Identity already does this. Can you import that one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why does Identity not have a ddoc comment?

Copy link
Member

Choose a reason for hiding this comment

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

No clue. Probably because it exposes a deficiency in the language that may be fixed in the future?

Copy link
Member

Choose a reason for hiding this comment

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

Can you import that one?

Hah, I didn't even realize this was std.traits that you were editing :) The edit to remove std.traits import threw me off too!

@schveiguy
Copy link
Member

nice, LGTM

@Hackerpilot
Copy link
Contributor Author

@schveiguy: Fixed

@schveiguy
Copy link
Member

Auto-merge toggled on

schveiguy added a commit that referenced this pull request Jun 22, 2015
@schveiguy schveiguy merged commit 693bf11 into dlang:master Jun 22, 2015
@schveiguy schveiguy mentioned this pull request Jun 23, 2015
@Hackerpilot Hackerpilot deleted the add-getSymbolsByUDA branch June 23, 2015 21:06
int d;
}

// Also checks the symbol itself
Copy link
Contributor

Choose a reason for hiding this comment

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

If foresee that including the symbol itself per default will lead to a lot of devs having to explicitly do an extra check for excluding the symbol from the result. I also think that is the most common case. So I would exclude the symbol itself and let devs explicitly include it if they need it.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

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.

6 participants