I think I really don't know what exactly do the UDAs do at the moment, judging from your reply.The only documentation was the original D.anounce post of yours. Is there a way I can get a reliable documentation on this? <div>
<br></div><div>Use cases:</div><div><br></div><div>1. I have a declaration with a UDA struct. I introspect the types I need and add their names to an array in that struct. read that struct in a static constructor and do necessary stuff with all those types. Is this possible currently?</div>
<div><br></div><div>2. I have some code, which must be run on any type, marked with a special UDA. Can I have that code executed without explicitly having to mix stuff in every module?</div><div><br></div><div>I guess the way UDAs were originally designed, they have absolutely nothing to do with what I envisioned.</div>
<div><br></div><div><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Nov 27, 2012 at 3:11 PM, Walter Bright <span dir="ltr"><<a href="mailto:newshound2@digitalmars.com" target="_blank">newshound2@digitalmars.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 11/27/2012 6:42 PM, Gor Gyolchanyan wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
AFAIK, currently UDAs are set at declaration site, are immutable and the<br>
declaration cannot get additional UDAs externally. Moreover, only global<br>
declarations can have UDAs, which removes some very useful possible uses<br>
of UDAs.<br>
</blockquote>
<br></div>
What very useful thing could be done with UDAs on local variables?<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Lack of mutable compile-time variables sometimes cripples the<br>
metaprogramming in D. For instance all classes, derived from a certain<br>
type must be dealt with in a special way, which requires a tuple of<br>
those types. Gathering a tuple of unrelated types is currently<br>
impossible, because that would require mutable compile-time variables.<br>
</blockquote>
<br></div>
I don't understand this. It is perfectly possible to create compile time tuple of (int, long, float, int*, S).<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Mutable compile-time variables would also be extremely useful for<br>
implementing a very powerful compile-time reflection library without the<br>
need for compiler magic. All you'd have to do is mix in a template in<br>
your class or your module and voila. The mixin would then add the<br>
introspected declarations to the central compile-time declaration<br>
repository.<br>
</blockquote>
<br></div>
I don't understand the difficulty here. UDAs are additive, so you could mixin your template in one space at the top, and it will apply to all the declarations nested under it, exactly like other attributes do now.<div class="im">
<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
There are also many cases when some actions need to happen in case a<br>
declaration gets a UDA of a specific type. For instance, a powerful RTTI<br>
library, which (when a type gets a dedicated RTTI-typed UDA) adds the<br>
run-time information about the class to the central registry at<br>
load-time.<br>
</blockquote>
<br></div>
That can be done now. Loop over the declarations, checking to see if each has a particular attribute.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This kind of stuff could be easily achieved using the<br>
constructors and destructors of the structures, being added to the UDAs<br>
of a declaration (in this case a class). The only missing thing for this<br>
to work is the ability for the constructor to see the declaration it's<br>
being put on. I'd personally expect there to be some sort of a<br>
__traits(<u></u>getAttributeDeclaration), which would evaluate to the symbol on<br>
which the enclosing type (a structure, a union or whatever) is being<br>
placed on as an attribute.<br>
</blockquote>
<br></div>
That could cause ugly forward reference issues, and also recall that a UDA can be applied to many declarations at once.<br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Bye,<br>Gor Gyolchanyan.<br>
</div>