opApply outside of struct/class scope

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 10 14:57:28 PDT 2014


On Sunday, 10 August 2014 at 19:01:18 UTC, Era Scarecrow wrote:
> On Sunday, 10 August 2014 at 18:58:50 UTC, Jonathan M Davis 
> wrote:
>> No overloaded operators in D can be put outside of a struct or 
>> class. They have to be member functions.
>
>  If I remember right, opApply was somewhat broken and only 
> worked correctly in a few cases. But that was 18 months ago, a 
> lot could have happened...

I'm not aware of opApply being broken, but I never use it, since 
in most cases where you might use opApply, you can use ranges, 
and they're far more flexible. But regardless, it's not legal to 
declare an overloaded operator outside of the type that it's for, 
so whether you're talking about opApply, opBinary, opAssign, or 
any other overloaded operator, declaring it as a free function 
like the OP is trying to do isn't going to work.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list