nothrow function callbacks in extern(C) code - solution

Mason McGill via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 22 02:52:48 PDT 2014


On Thursday, 19 June 2014 at 23:41:25 UTC, H. S. Teoh via 
Digitalmars-d wrote:
> Pretty soon, we need an attribute algebra to express these 
> complicated
> relationships.
>
> It would be nice to have a solution that can handle all of 
> these cases
> without exploding complexity in the syntax.

Here's one idea:

Attributes can be thought of as "declarative" compile-time 
parameters--they don't directly define a computation, but they 
feel like compile-time parameters in that
   - They are variable in number.
   - They may take on many possible values.
   - They may be parameterized (like `extern`).
   - They play a role in overload resolution.
   - Their combinations may lead to combinatorial explosions
     that can hopefully be mitigated with metaprogramming.

My point is, many of the problems we're encountering with 
attributes have already been solved (via templates, tuples, CTFE, 
`static if`, etc.)

Attribute propagation would be simple (not trivial, but 
appropriately simple) for user-defined attributes, because they 
can be arbitrary expressions. If built-in attributes were just 
treated as pre-defined symbols, they could be manipulated with 
templates and CTFE:

   enum mayThrow(alias func) =
       staticIndexOf!(nothrow, functionAttributes!func) == -1;

   template throwsLike(alias func) {
       static if (mayThrow!func)
           enum throwsLike = tuple().expand;
       else
           enum throwsLike = nothrow;
   }

   void call(alias func)() @throwsLike!func {
       func();
   }

(This thread may be relevant:
http://forum.dlang.org/thread/hfmulninvghjntqkpguk@forum.dlang.org)


More information about the Digitalmars-d mailing list