Skip to content

Commit 74a4641

Browse files
committed
Improve support for Tuples
Issues Return tuple of arrays #478 and StdVector of Tuple #469
1 parent 566e2d9 commit 74a4641

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/CxxWrap.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ map_julia_arg_type(t::Type{CxxPtr{CxxChar}}) = Union{PtrTypes{Cchar}, String}
591591
map_julia_arg_type(t::Type{<:Array{T}}) where {T <: CxxNumber} = Union{t, Array{julia_int_type(T)}}
592592
map_julia_arg_type(t::Type{<:Array{Ptr{T}}}) where {T <: CxxNumber} = Union{t, Array{Ptr{julia_int_type(T)}}}
593593
map_julia_arg_type(t::Type{ConstCxxPtr{CxxChar}}) = Union{ConstPtrTypes{Cchar}, String}
594+
map_julia_arg_type(::Type{T}) where {T<:Tuple} = Tuple{map_julia_arg_type.(T.parameters)...}
594595

595596
# names excluded from julia type mapping
596597
const __excluded_names = Set([

src/StdLib/StdVector.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ StdVector(v::Vector{Bool}) = StdVector{CxxBool}(v)
3434
Base.IndexStyle(::Type{<:StdVector}) = IndexLinear()
3535
Base.size(v::StdVector) = (Int(cppsize(v)),)
3636
Base.getindex(v::StdVector, i::Int) = cxxgetindex(v, i)[]
37+
Base.getindex(v::StdVector{<:Tuple}, i::Int) = cxxgetindex(v, i)
3738
Base.setindex!(v::StdVector{T}, val, i::Int) where {T} = cxxsetindex!(v, convert(T, val), i)
3839

3940
@cxxdereference function Base.push!(v::StdVector, x)

test/containers.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,15 @@ let a1 = [UInt8(3)], a2 = [UInt8(5)]
6060
@test Containers.uint8_arrayref([pointer(a1), pointer(a2)]) == 8
6161
end
6262

63-
end
63+
let tup = (1.0, Int32(2), true)
64+
@test Containers.copy_tuple(tup) == tup
65+
end
66+
67+
let artup = ([1.0,1.0,1.0], [3.0,3.0])
68+
@test Containers.read_array_tuple(artup) == [1.0, 1.0, 1.0, 3.0, 3.0]
69+
@test Containers.make_array_tuple() == ([1.0,2.0], [3.0])
70+
end
71+
72+
@test Containers.make_tuple_vector() == [(1.0,2.0), (3.0,4.0)]
73+
74+
end

0 commit comments

Comments
 (0)