Skip to content

Commit

Permalink
Add basic support for std::deque
Browse files Browse the repository at this point in the history
  • Loading branch information
abdoei authored and barche committed Mar 22, 2023
1 parent 7b27b1c commit f124881
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/CxxWrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,8 @@ ConstCxxPtr, ConstCxxRef, CxxRef, CxxPtr,
CppEnum, ConstArray, CxxBool, CxxLong, CxxULong, CxxChar, CxxChar16, CxxChar32, CxxWchar, CxxUChar, CxxSignedChar,
CxxLongLong, CxxULongLong, ptrunion, gcprotect, gcunprotect, isnull

using .StdLib: StdVector, StdString, StdWString, StdValArray, StdThread
using .StdLib: StdVector, StdString, StdWString, StdValArray, StdThread, StdDeque

export StdLib, StdVector, StdString, StdWString, StdValArray, StdThread
export StdLib, StdVector, StdString, StdWString, StdValArray, StdThread, StdDeque

end # module
13 changes: 13 additions & 0 deletions src/StdLib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,17 @@ 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)[]
Base.setindex!(v::StdDeque{T}, val, i::Int) where {T} = cxxsetindex!(v, convert(T,val), i)
Base.push!(v::StdDeque, x) = push_back!(v, x)
Base.pushfirst!(v::StdDeque, x) = push_front!(v, x)
Base.pop!(v::StdDeque) = pop_back!(v)
Base.popfirst!(v::StdDeque) = pop_front!(v)
Base.resize!(v::StdDeque, n::Integer) = resize!(v, n)
end
13 changes: 13 additions & 0 deletions test/stdlib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,17 @@ let
@test valarr2[2] == 6
end


let
@show "test deque"
deque1 = StdDeque{Int64}()
@test length(deque1) == 0
push!(deque1, 7)
push!(deque1, 9)
@test length(deque1) == 2
deque2 = deque1
popfirst!(deque2)
@test length(deque2) == 1
end

end

0 comments on commit f124881

Please sign in to comment.