Hopefully a simple question...

kinke via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 13 10:04:45 PST 2017


On Friday, 13 January 2017 at 16:56:43 UTC, WhatMeWorry wrote:
> A vec and scalar can't be added together.  So why (or how) is 
> the glm code working?

The C++ source disagrees: 
https://github.com/g-truc/glm/blob/master/glm/detail/type_vec2.hpp#L219
It works via operator overloading, and adding a scalar simply 
means adding it to all vector components.

In your case, you may get away by simply using the types in 
`core.simd`, such as `float2` instead of your `Vector` template. 
Otherwise, D operator overloading is way more elegant in D than 
in C++, see https://dlang.org/spec/operatoroverloading.html.


More information about the Digitalmars-d-learn mailing list