Comments (4)
Note that your operator definition is recursive. Compile with -O2 and.. infinite loop o/
from rock.
Yeah, silly example. :P
But I also really want this. It's nice to put operator overloads inside the class they actually belong to.
from rock.
Well, I have nothing against implementing this, but there will be a slight difference in semantics from the 'operator overloading outside of class' way.
Why? Easy.
Operator overloads outside a type definition (not necessarily only a class) allow to add operator overloads to any type. And I mean any. Especially if it's defined in completely another module, and especially if the type is defined in a library which you can't change the source (that can and will happen eventually, with the upcoming libs format allowing separate compilation)
The problem is that, if you do the following:
- Define a 'List' class in structs/List
- Define operator [] for List in structs/List
- Define an 'ArrayList' class in structs/ArrayList
...then if you only import ArrayList, you won't get operator overloading for it. Why does that happen? Well, rock can't take into account the operator oveloading in List, otherwise - how could it choose? There might be operator overloads for some super-class of ArrayList in an other module that ArrayList imports. It would be messy and thus, that's not how it works.
It's handy sometimes, because it allows you to override existing operator overloads if you don't like them. If you want to monitor ArrayList accesses in your application, just define an operator [] to ArrayList and import it everywhere - if it's imported after List/ArrayList, it'll be chosen instead (or at least should be - report a bug if it's not.)
So now, how will that be handled with operator overloads in class? Well operator overloads in class should, in my opinion, behave different: ie. if you define operator overloads within the List class, then only impoting ArrayList should give you those operator overloads, ie. member operator overloads would be inherited.
That may be seen as a small difference for the day-to-day user but important enough that it should be discussed on this issue imho. If everyone agrees to that behavior then we'll be able to get started on the implementation.
from rock.
Woop! #583 is a duplicated and has been closed in the 'templates' branch - will be in 0.9.6
from rock.
Related Issues (20)
- pkg-config/CustomPkg flags aren't passed to additionals HOT 2
- Rock cannot find sdk when run from make HOT 2
- Weird behaviour with setters calling associated getter HOT 7
- The way rock constructs class information can lead to data races in seemingly unrelated code HOT 3
- Unexpectedly "good" behaviour from ooc arrays HOT 4
- So, is OOC development still onging? HOT 5
- Rock aborts with interfaces HOT 1
- Problems making after cloning repo HOT 4
- Problem installing: GC_jmp_buf multiple definition HOT 2
- The top 5 bugs? HOT 3
- Template type instances generated in separate modules do not generate include statements in C code HOT 1
- Wrong cast to non scalar type, and some other problems. HOT 3
- Rock parses function arguments with default values incorrectly HOT 1
- 'this' as default parameter value in a function refers to the wrong object HOT 2
- Static variables are not maintained correctly HOT 4
- Add newcomer label to issues HOT 1
- Allow implementing interfaces after type declaration HOT 1
- rock generates invalid C code when trying to access an interface's generic type HOT 2
- Funcs should behave as Closures with extra type information. HOT 7
- rock sometimes segfaults when classes try to implement interfaces
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rock.