Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract type IdenticalElementArray{T,N} <: AbstractArray{T,N} end
- Base.size(x::IdenticalElementArray) = x.dims
- Base.IndexStyle(x::IdenticalElementArray) = IndexLinear()
- macro identicalelementarray(TypeName, elem)
- T = typeof(eval(elem))
- esc(quote
- struct $TypeName{T,N} <: IdenticalElementArray{T,N}
- dims::NTuple{N,Int}
- end
- ($TypeName)(dims...) = ($TypeName){$(typeof(elem)),length(dims)}(dims)
- Base.getindex(x::$TypeName, idx...) = $elem
- end)
- end
- @identicalelementarray Foo "foo"
- Foo(1,2,3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement