On 4/6/12, Nick Sabalausky <[email protected]> wrote:
> Regardless, I've realized I can probably just detect it thanks to the
> brilliant magic that is __traits(compiles,...)  (Take that, "autoconf"! ;))

Yeah traits is great. Btw, a side-tip to library authors (not aimed at
Nick): Please don't drown compilation errors with __traits(compiles)
if you're instantiating a template from user-code, because it makes it
hard for the user to figure out that a template was never
instantiated.

E.g. msgpack-d allows you to define a custom serialization function
that it will invoke if found in a struct/class. But this function has
to be a template of the form:
void toMsgpack(Packer)(ref Packer packer) const { }

The problem is, if there's invalid code in the template the compiler
won't verify it until the template is instantiated. Msgpack itself
instantiates it, but it first does a check with __traits(compiles),
and if the template doesn't instantiate it just skips calling the
function altogether. So then the user has to wonder why his function
was never called.
_______________________________________________
dmd-beta mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/dmd-beta

Reply via email to