Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

operator overloads in types #583

Closed
nddrylliog opened this issue Feb 14, 2013 · 2 comments
Closed

operator overloads in types #583

nddrylliog opened this issue Feb 14, 2013 · 2 comments
Labels
Milestone

Comments

@nddrylliog
Copy link
Member

ie. be able to write that:

MyArray: cover template <T> {
    length: Int
    data: T*

    init: func@ (=length) {
        data = gc_malloc(T size * length)
    }

    get: func (index: Int) -> T {
        _checkIndex(index)
        data[index]
    }

    set: func@ (index: Int, value: T) {
        _checkIndex(index)
        data[index] = value
    }

    _checkIndex: func (index: Int) {
        if (index < 0 || index >= length) {
            Exception new("Out of bounds array access: %d should be in %d..%d" \
                format(index, 0, length)) throw()
        }
    }

    operator [] (i: Int) -> T {
        get(i)
    }

    operator []= (i: Int, v: T) {
        set(i, v)
    }
}

It'll also fix weird things like: using a lib that returns a List, and then you try to index it with [] but it doesn't work because you don't import ArrayList/List yourself.

@alexnask
Copy link
Collaborator

Cough cough #33 cough cough

nddrylliog added a commit that referenced this issue Feb 14, 2013
@nddrylliog
Copy link
Member Author

Closed in 6ec80f5

nddrylliog added a commit that referenced this issue Feb 14, 2013
…ter). Still no inheritance.. will see about that laterz.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants