You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function StructArrays.createinstance(::Type{T}, x, args...) where {T<:MyType}
207
209
names, types =getnamestypes(T)
208
210
MyType(x, NamedTuple{names, types}(args))
@@ -303,3 +305,69 @@ julia> s
303
305
Foo(44, "d")
304
306
Foo(55, "e")
305
307
```
308
+
309
+
In the above example "for structures with non-standard data layout" our `MyType` was composed of `data` of type `Float64` and `rest` of type `NamedTuple`. In many practical cases where there are custom types involved it's hard for StructArrays to automatically widen the types in case they are heterogeneous. The following example demonstrates a widening method in that scenario.
310
+
311
+
```julia
312
+
struct MyType1{T, Names, Types}
313
+
data::T
314
+
rest::NamedTuple{Names, Types}
315
+
end
316
+
317
+
MyType1(x; kwargs...) =MyType1(x, values(kwargs))
318
+
319
+
# and a source of custom type data
320
+
struct location{U}
321
+
x::U
322
+
y::U
323
+
end
324
+
struct region{G<:Array{location}}
325
+
area::G
326
+
end
327
+
328
+
function Base.getproperty(x::MyType1, field::Symbol)
0 commit comments