[Issue 11042] Inconsistent "static condition" behaviors

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Sep 15 04:45:34 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=11042


Andrej Mitrovic <andrej.mitrovich at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich at gmail.com


--- Comment #2 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-09-15 04:45:33 PDT ---
I would find it even more useful if we extended this to templates, for example
here's the workaround code I have to use in one of my libraries:

alias storages = ParameterStorageClassTuple;  // from Phobos

/** 
    Check whether $(D T) is a handler function which 
    can be called with the $(D Types). 
*/
template isEventHandler(T, Types...)
    if (isSomeFunction!T)
{
    alias stores = storages!T;

    // eager evaluation workaround
    static if (!stores.length)
        enum bool isEventHandler = false;
    else
        enum bool isEventHandler = is(typeof(T.init(Types.init))) &&
                                   stores[0] == stcType.scope_ &&
                                   is(ReturnType!T == void);
}

If I'm not using this "static if", the "stores[0]" code will issue a compiler
error (out of bounds) if there are no parameters. But,
"is(typeof(T.init(Types.init)))" would already fail before it, however it's not
lazy so "stores[0]" is evaluated eagerly and the compiler emits an error.

Can we do anything about this? Perhaps enabling lazy evaluation for manifest
constants in an eponymous template would work.. I'm not sure.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list