Skip to content

Commit ddc24d7

Browse files
committed
add copyto! and unsafe_copyto!
1 parent 50c6b36 commit ddc24d7

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ Currently, the `@compat` macro supports the following syntaxes:
273273

274274
* `unshift!` and `shift!` are now `pushfirst!` and `popfirst!` ([#25100]).
275275

276+
* `copy!` and `unsafe_copy!` are now `copyto!` and `unsafe_copy!` ([#24808]).
277+
276278
* `ipermute!` is now `invpermute!` ([#25168]).
277279

278280
## New macros
@@ -435,4 +437,4 @@ includes this fix. Find the minimum version from there.
435437
[#25162]: https://github.com/JuliaLang/julia/issues/25162
436438
[#25165]: https://github.com/JuliaLang/julia/issues/25165
437439
[#25168]: https://github.com/JuliaLang/julia/issues/25168
438-
[#25113]: https://github.com/JuliaLang/julia/issues/25113
440+
[#25113]: https://github.com/JuliaLang/julia/issues/25113

src/Compat.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,13 @@ end
10701070
replace(s, first(pat_rep), last(pat_rep), count)
10711071
end
10721072

1073+
# 0.7.0-DEV.3057
1074+
@static if !isdefined(Base, :copyto!)
1075+
const copyto! = Base.copy!
1076+
const unsafe_copyto! = Base.unsafe_copy!
1077+
export copyto!, unsafe_copyto!
1078+
end
1079+
10731080
@static if VERSION < v"0.7.0-DEV.3025"
10741081
import Base: convert, ndims, getindex, size, length, eltype,
10751082
start, next, done, first, last

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,14 @@ let coolvec = [1,2,3]
10691069
@test popfirst!(coolvec) == 0
10701070
end
10711071

1072+
# 0.7.0-DEV.3057
1073+
let A = [0, 0, 0], B = [1, 2, 3]
1074+
@test copyto!(A, B) === A == B
1075+
end
1076+
let A = [0, 0, 0], B = [1, 2, 3]
1077+
@test unsafe_copyto!(A, 2, B, 1, 1) === A == [0, 1, 0]
1078+
end
1079+
10721080
# 0.7.0-DEV.3173
10731081
@test invpermute!(permute!([1, 2], 2:-1:1), 2:-1:1) == [1, 2]
10741082

0 commit comments

Comments
 (0)