Netflix opensources its first D library: Vectorflow
Nordlöw via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Tue Aug 8 11:51:26 PDT 2017
On Tuesday, 8 August 2017 at 18:40:08 UTC, Nordlöw wrote:
> On Thursday, 3 August 2017 at 04:40:05 UTC, Matt wrote:
>> Also note, one of the main advantages of Eigen is the whole
>> lazy evaluation of expressions for compound operations.
>>
>> I haven't dug in the source, but it's my understanding it's
>> done through a lot of compile time C++ template hacking
>
> Note that D provides
>
> __traits(isRef, Symbol)
To clarify here's an incomplete snippet that should clarify:
auto add(A, B)(A a, B b)
if (isSomeArithmeticType!A &&
isSomeArithmeticType!B)
{
static if (__traits(isRef, a) &&
__traits(isRef, b)) // both `a` and `b` are l-values
{
return a + b; // fully eager evaluation
}
else static if (__traits(isRef, a)) // `b` is an r-value
{
// `b` can incremented by `a` and returned by move (reused)
}
else static if (__traits(isRef, b)) // `a` is an r-value
{
// `a` can incremented by `b` and returned by move (reused)
}
else // both `a` and `b` are r-values
{
return Add(a,b); // delay evaluation
}
}
More information about the Digitalmars-d-announce
mailing list