Skip to content

Commit 03d7986

Browse files
committed
add similar_type
1 parent 6d32a69 commit 03d7986

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "StaticArraysCore"
22
uuid = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
3-
version = "1.0.1"
3+
version = "1.1.0"
44

55
[compat]
66
julia = "1.6"

src/StaticArraysCore.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,26 @@ const SizedVector{S,T} = SizedArray{Tuple{S},T,1,1}
269269

270270
const SizedMatrix{S1,S2,T} = SizedArray{Tuple{S1,S2},T,2}
271271

272+
"""
273+
similar_type(static_array)
274+
similar_type(static_array, T)
275+
similar_type(array, ::Size)
276+
similar_type(array, T, ::Size)
277+
278+
Returns a constructor for a statically-sized array similar to the input array
279+
(or type) `static_array`/`array`, optionally with different element type `T` or size
280+
`Size`. If the input `array` is not a `StaticArray` then the `Size` is mandatory.
281+
282+
This differs from `similar()` in that the resulting array type may not be
283+
mutable (or define `setindex!()`), and therefore the returned type may need to
284+
be *constructed* with its data.
285+
286+
Note that the (optional) size *must* be specified as a static `Size` object (so the compiler
287+
can infer the result statically).
288+
289+
New types should define the signature `similar_type(::Type{A},::Type{T},::Size{S}) where {A<:MyType,T,S}`
290+
if they wish to overload the default behavior.
291+
"""
292+
function similar_type end
293+
272294
end # module

0 commit comments

Comments
 (0)