www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17734] New: __traits(isRef) cannot currently be used to

https://issues.dlang.org/show_bug.cgi?id=17734

          Issue ID: 17734
           Summary: __traits(isRef) cannot currently be used to
                    distinguish l-value from r-value passing of `this`
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: per.nordlow gmail.com

__traits(isRef) cannot currently be used to distinguish l-value from r-value
passing of `this`:

# l-value passing:
S s = 42;
s.f();

# r-value passing:
S(42).f();

given that

struct SS 
{
    int x; 
    void f(int x);
}

This severly limits the possibilities of implenting C++-style expression
templates to realize lazy evaluation in operator overloading in arithmetic
types.

If this limitation were to be fixed, libraries such as gmp-d (which wrap the
C-implementation GNU MP) could implement lowering of expressions such as (in
the gmp case):

    Z result = base^^exp % modulo

to the builtin

    __gmpz_powm(result._ptr, base._ptr, expr._ptr, modulo._ptr)

See also: https://github.com/nordlow/gmp-d/#limitations

--
Aug 08