Perform size-based dispatch using the `Size` trait
masterThe Size trait provides an abstract representation of a static array's dimensions, allowing the compiler to reason about them. This is useful for performing specialized dispatch based on array dimensions.
Equivalent ways to construct a Size object:
Size{(dims...,)}()Size(dims...)Size(sa::StaticArray)Size(SA)(whereSA <: StaticArray)
Example of size-based dispatch:
det(x::StaticMatrix) = _det(Size(x), x)
_det(::Size{(1,1)}, x::StaticMatrix) = x[1,1]
_det(::Size{(2,2)}, x::StaticMatrix) = x[1,1]*x[2,2] - x[1,2]*x[2,1]# Using Size for reshaping or construction
reshape(svector, Size(2,2))
SizedMatrix{3,3}(rand(3,3))