[Issue 5934] Finite recursive templates are not allowed
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Fri May  6 07:59:40 PDT 2011
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=5934
--- Comment #1 from Maksim Zholudev <maximzms at gmail.com> 2011-05-06 07:55:47 PDT ---
The following code works, but such workarounds are annoying:
----------
struct Foo
{
    auto opUnary(string op)()
    if(op == "-")
    {
        return Negation!(typeof(this))(this);
    }
}
struct Negation(T)
{
    T statement;
    auto opUnary(string op)()
    if(op == "-")
    {
        return MakeNeg(this); // The return type is "Negation!(Negation!(T))"
    }
}
// Function that makes the recursion implicit
auto MakeNeg(T)(T stat)
{
    return Negation!(T)(stat);
}
void main()
{
    Foo a;
    auto b = -a; // no errors
    auto c = -(-a); // no errors
}
----------
-- 
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