Skip to content

Commit

Permalink
Provide 0.6 implementation of collect for previous releases
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Apr 19, 2017
1 parent 49e0235 commit cef63c1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `@compat Base.IndexStyle(::Type{<:MyArray}) = IndexLinear()` and `@compat Base.IndexStyle(::Type{<:MyArray}) = IndexCartesian()` to define traits for abstract arrays, replacing the former `Base.linearindexing{T<:MyArray}(::Type{T}) = Base.LinearFast()` and `Base.linearindexing{T<:MyArray}(::Type{T}) = Base.LinearSlow()`, respectively.

* `Compat.collect(A)` returns an Array even on 0.5, no matter what indices the array `A` has. [#21257]

## Module Aliases

* In 0.6, some 0.5 iterator functions have been moved to the `Base.Iterators`
Expand Down Expand Up @@ -363,3 +365,4 @@ includes this fix. Find the minimum version from there.
[#20500]: https://github.com/JuliaLang/julia/issues/20500
[#18629]: https://github.com/JuliaLang/julia/pull/18629
[#21346]: https://github.com/JuliaLang/julia/pull/21346
[#21257]: https://github.com/JuliaLang/julia/pull/21257
14 changes: 14 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,20 @@ else
using Base: StringVector
end

# https://github.com/JuliaLang/julia/pull/21257
if v"0.5.0" <= VERSION < v"0.6.0-pre.beta.28"
collect(A) = collect_indices(indices(A), A)
collect_indices(::Tuple{}, A) = copy!(Array{eltype(A)}(), A)
collect_indices(indsA::Tuple{Vararg{Base.OneTo}}, A) =
copy!(Array{eltype(A)}(map(length, indsA)), A)
function collect_indices(indsA, A)
B = Array{eltype(A)}(map(length, indsA))
copy!(B, CartesianRange(indices(B)), A, CartesianRange(indsA))
end
else
const collect = Base.collect
end

include("to-be-deprecated.jl")

end # module Compat
1 change: 1 addition & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OffsetArrays
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,15 @@ let x = fill!(StringVector(5), 0x61)
@test pointer(x) == pointer(Compat.UTF8String(x))
end

# collect
if VERSION >= v"0.5.0"
using OffsetArrays
a = OffsetArray(1:3, -1:1)
b = Compat.collect(a)
@test indices(b) === (Base.OneTo(3),)
@test b == [1,2,3]
end

include("to-be-deprecated.jl")

nothing

0 comments on commit cef63c1

Please sign in to comment.