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

Add StdFill #420

Merged
merged 6 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .github/workflows/test-linux-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
defaults:
run:
shell: bash

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
Expand All @@ -19,11 +19,11 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- '1.10'
- 'nightly'
- "1.7"
- "1.10"
- "nightly"
os:
- macOS-latest
- macos-13
- ubuntu-latest
arch:
- x64
Expand Down Expand Up @@ -65,4 +65,3 @@ jobs:
cd ../..
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest

23 changes: 11 additions & 12 deletions .github/workflows/test-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
defaults:
run:
shell: bash

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
Expand All @@ -19,9 +19,9 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- '1.10'
- 'nightly'
- "1.7"
- "1.10"
- "nightly"
os:
- windows-latest
arch:
Expand Down Expand Up @@ -58,20 +58,19 @@ jobs:
continue-on-error: true
if: ${{ matrix.arch == 'x86'}}
run: |
cd libcxxwrap && mkdir build && cd build
cmake -G "Visual Studio 17 2022" -A Win32 -DOVERRIDES_PATH=$HOMEDRIVE/$HOMEPATH/.julia/artifacts/Overrides.toml -DOVERRIDE_ROOT=./ -DAPPEND_OVERRIDES_TOML=ON ..
cd libcxxwrap && mkdir build && cd build
cmake -G "Visual Studio 17 2022" -A Win32 -DOVERRIDES_PATH=$HOMEDRIVE/$HOMEPATH/.julia/artifacts/Overrides.toml -DOVERRIDE_ROOT=./ -DAPPEND_OVERRIDES_TOML=ON ..
- name: Config 64bit
continue-on-error: true
if: ${{ matrix.arch == 'x64'}}
run: |
cd libcxxwrap && mkdir build && cd build
cmake -G "Visual Studio 17 2022" -A x64 -DOVERRIDES_PATH=$HOMEDRIVE/$HOMEPATH/.julia/artifacts/Overrides.toml -DOVERRIDE_ROOT=./ -DAPPEND_OVERRIDES_TOML=ON ..
cd libcxxwrap && mkdir build && cd build
cmake -G "Visual Studio 17 2022" -A x64 -DOVERRIDES_PATH=$HOMEDRIVE/$HOMEPATH/.julia/artifacts/Overrides.toml -DOVERRIDE_ROOT=./ -DAPPEND_OVERRIDES_TOML=ON ..
- name: Build libcxxwrap
continue-on-error: true
run: |
cd libcxxwrap/build
cmake --build . --config Release
cd libcxxwrap/build
cmake --build . --config Release

- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest

7 changes: 3 additions & 4 deletions src/StdLib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ Base.size(v::StdValArray) = (Int(cppsize(v)),)
Base.getindex(v::StdValArray, i::Int) = cxxgetindex(v,i)[]
Base.setindex!(v::StdValArray{T}, val, i::Int) where {T} = cxxsetindex!(v, convert(T,val), i)

function StdDeque(v::Vector{T}) where {T}
return StdDeque{T}(v, length(v))
end

Base.IndexStyle(::Type{<:StdDeque}) = IndexLinear()
Base.size(v::StdDeque) = (Int(cppsize(v)),)
Base.getindex(v::StdDeque, i::Int) = cxxgetindex(v,i)[]
Expand All @@ -212,4 +208,7 @@ Base.size(v::StdQueue) = (Int(cppsize(v)),)
Base.push!(v::StdQueue, x) = push_back!(v, x)
Base.first(v::StdQueue) = front(v)
Base.pop!(v::StdQueue) = pop_front!(v)


Base.fill!(v::T, x) where T <: Union{StdVector, StdValArray, StdDeque} = StdFill(v, x)
PraneethJain marked this conversation as resolved.
Show resolved Hide resolved
end
28 changes: 28 additions & 0 deletions test/stdlib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,32 @@ let
@test length(queue) == 1
end

@testset "StdFill" begin
@testset "fill StdVector" begin
v = StdVector{Int64}([1, 2, 3, 4, 5])
fill!(v, 1)
for x in v
@test x == 1
end
end

@testset "fill StdValArray" begin
v = StdValArray([1.0, 2.0, 3.0])
fill!(v, 2)
for x in v
@test x == 2
end
end

@testset "fill StdDeque" begin
deq = StdDeque{Int64}()
for i = 1:10
push!(deq, i)
end
fill!(deq, 3)
for x in deq
@test x == 3
end
end
end
end
Loading