On Sun, 29 Mar 2015 17:02:53 +0000, D. Martinez wrote:

> 2. The function attributes: @nogc nothrow. These relate to my realtime
> audio thread because I want neither of these things to occur; my thread
> runs unmanaged by the D runtime and I appreciate the static checking.
> But I don't use it: why?
> I use writefln a lot to debug my implementations, which is incompatible
> with either assumption.

that's why i wrote `iv.writer` with compile-time format strings and nogc 
conversions for numbers. it still using `to!` for other objects 
(including floating point numbers, but this can be fixed). output strings 
and integral numbers is enough for debug logs for me. althru it's not 
"vanilla" D, it's still very easy to backport to D2 (actually, "sed" will 
do). it is build on templates, so it infers attributes. most of the time 
this is "nothrow @nogc".

and, to stop talking about myself, here is some hackery for you:

  import std.traits;

  auto assumeNoTrowNoGC(T) (T t)
  if (isFunctionPointer!T || isDelegate!T)
    enum attrs = functionAttributes!T|
    return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) t;

  void myFuncThatDoesGC () {
    throw new Exception("hello!");

  void anotherFunction () nothrow @nogc {
    //myFuncThatDoesGC(); // alas, but
    assumeNoTrowNoGC(() { myFuncThatDoesGC(); })(); // yay!

but don't tell anyone that you got this code from me, or Type Nazis will 
kill me! ;-)

Attachment: signature.asc
Description: PGP signature

Reply via email to