On Fri, Jan 4, 2013 at 9:59 PM, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
On 1/4/13 3:51 PM, Walter Bright wrote:
 
So, I'm testing how to transfer UDA from one symbol to another.


This will do the transfer:

import std.stdio;
void main()
{
@(3, "hello") int i = 10;
@(__traits(getAttributes, i)) double d2;
writeln("[",__traits(getAttributes, d2), "]");
}

Yes, I know. I just want to automate the process. I want a function or some piece of code that can propagate attributes. 
For example, say I receive a piece of unvalidated input. I test it and it's OK. I want to return it, with a new attribute (say, Validated() ),while keeping the input attributes. Since it seems a common need, I was looking for a way to abstract the process somewhat.

For now, we would return a Validated(initialValue) struct. I just want to see how attributes can be used here. It seems that:

@(Validated, __traits(getAttributes, input)) InputType temp;
return temp;

do not work.

If attribute manipulation cannot be isolated in easily reusable code, that would be sad.



Andrei:

For transfer templates are better than attributes.

Could you please give an example?