Skip to content

Conversation

@aminya
Copy link
Collaborator

@aminya aminya commented Jul 1, 2020

super constructor inheritance when the child does not have any additional fields

@class Animal begin
    x
    Animal(x, y) = new(x)
end

function Animal(x, y, z)
    return Animal(x+y+z)
end

@class Dog <: Animal begin
end

Dog(1,2)
Dog(1,2,3)

@aminya aminya force-pushed the constructor_inheritance branch 2 times, most recently from 9569d29 to 4dd7dea Compare July 1, 2020 14:45
@aminya aminya force-pushed the constructor_inheritance branch from 4dd7dea to d9e522e Compare July 2, 2020 01:41
aminya added 7 commits July 2, 2020 01:06
benchmark:
```julia
using Classes
using BenchmarkTools
struct Foo{T}
    x::T
    y::T
    z::T
end

f = Foo(1,2,3)

fnames = [:x, :y, :z]

function t1(f, fnames)
    x = (getfield(f, arg) for arg in fnames)
    return Foo(x...)
end

x = @Btime t1($f, $fnames)

function t2(f, fnames)
    x = getfield.(Ref(f), fnames)
    return Foo(x...)
end

x = @Btime t2($f, $fnames)

```
@aminya aminya force-pushed the constructor_inheritance branch from 384442d to 86a48c7 Compare July 2, 2020 06:34
@aminya aminya merged commit 3cbb6c1 into rjplevin:master Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant