www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.contracts.enforceEx

reply Steve Teale <steve.teale britseyeview.com> writes:
Perhaps a bug? If this is written as a normal function template it seems 
to work the same way, but has the advantage of generating better Ddoc 
information. That is:

T enforceEx(E, T)(T value, lazy string msg = "")
{
    if (!value) throw new E(msg);
        return value;
}

instead of:

template enforceEx(E)
{
    T enforceEx(T)(T value, lazy string msg = "")
    {
        if (!value) throw new E(msg);
        return value;
    }
}
Feb 08 2010
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
Steve Teale wrote:
 Perhaps a bug? If this is written as a normal function template it seems 
 to work the same way, but has the advantage of generating better Ddoc 
 information. That is:
 
 T enforceEx(E, T)(T value, lazy string msg = "")
 {
     if (!value) throw new E(msg);
         return value;
 }
 
 instead of:
 
 template enforceEx(E)
 {
     T enforceEx(T)(T value, lazy string msg = "")
     {
         if (!value) throw new E(msg);
         return value;
     }
 }

The function was indeed written that way to navigate around a limitation. Andrei
Feb 08 2010