<br><br><div class="gmail_quote">On Mon, Apr 19, 2010 at 05:21, Justin Spahr-Summers <span dir="ltr"><<a href="mailto:Justin.SpahrSummers@gmail.com">Justin.SpahrSummers@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div>You can use some expression tuple magic to accomplish something like<br></div>
that:<br>
<br>
bool check(alias func, EL ...)() {<br>
GError* err;<br>
bool ok = func(EL, &err);<br>
<div class="im"> if (!ok)<br>
throw new Exception((*err).message);<br>
<br>
</div> return ok;<br>
}<br>
<br>
// used like:<br>
check!(fooXXX, arg1, ..., argN);<br>
<br></blockquote><div><br>But in this case, you need to know the ELs at compile-time. You can make them run-time values that way:<br><br>bool check(alias func, EL ...)(EL el) {<br>
GError* err;<br>
bool ok = func(el, &err);<br>
<div class="im"> if (!ok)<br>
throw new Exception((*err).message);<br>
<br>
</div> return ok;<br>
}<br>
<br>
// used like:<br>
check!fooXXX(arg1, ..., argN);<br><br><br>Of course, it'd be nice to check the EL at CT to see if they correspond to func parameters types. I don't know if you can do this with C functions, but for D funcs you can add:<br>
<br>import std.traits;<br>bool check(alias func, EL ...)(EL el) if (is(ParameterTypeTuple!func[0..$-1] == TypeTuple!(EL, GError*))<br>{<br>...<br><br>It's a bit strict, as it doesn't deal with implicit conversions.<br>
<br>Cheers,<br><br> Philippe<br><br></div></div>