custom attribute proposal (yeah, another one)

bls bizprac at orange.fr
Fri Apr 6 11:08:47 PDT 2012


On 04/06/2012 10:51 AM, bls wrote:
> On 04/06/2012 07:04 AM, Manu wrote:
>> I think Johannes proposal already nails it. What benefits would be
>> merged from this proposal? How would they influence the design?
>>
>> On 04/06/2012 11:41 AM, Johannes Pfau wrote:
>>
>> Declaring a custom attribute:
>> ---------
>> module std.something;
>>
>> struct Author
>> {
>> string name;
>> public this(string name)
>> {
>> this.name <http://this.name> = name;
>> }
>> }
>> ---------
>

Oh the joy of copy and paste ..

struct Annotation  //Throw in all your annotations
{

     Variant[] [string] map;

     Variant[] opDispatch(string key)()
     {
                return map[key];
     }

     // Single value
     void opDispatch(string key, T) (T t )
     if ( !isArray!T && !isTuple!T )
     {
        	map[key] ~= to!Variant(t);
	return;
      }
     // Allow ....Array and Tuple too
}


More information about the Digitalmars-d mailing list