@@ -173,10 +173,26 @@ new_quantity(::Type{Q}, l, r) where {Q<:AbstractUnionQuantity} = constructorof(Q
173
173
dim_type (:: Type{Q} ) where {T,D<: AbstractDimensions ,Q<: AbstractUnionQuantity{T,D} } = D
174
174
dim_type (:: Type{<:AbstractUnionQuantity} ) = DEFAULT_DIM_TYPE
175
175
176
+ """
177
+ constructorof(::Type{<:AbstractDimensions})
178
+ constructorof(::Type{<:AbstractUnionQuantity})
179
+
180
+ Return the constructor of the given type. This is used to create new objects
181
+ of the same type as the input. Overload a method for a new type, especially
182
+ if you need custom behavior.
183
+ """
176
184
constructorof (:: Type{<:Dimensions} ) = Dimensions
177
185
constructorof (:: Type{<:Quantity} ) = Quantity
178
186
constructorof (:: Type{<:GenericQuantity} ) = GenericQuantity
179
187
188
+ """
189
+ with_type_parameters(::Type{<:AbstractDimensions}, ::Type{R})
190
+ with_type_parameters(::Type{<:AbstractUnionQuantity}, ::Type{T}, ::Type{D})
191
+
192
+ Return the type with the given type parameters instead of the ones in the input type.
193
+ This is used to get `Dimensions{R}` from input `(Dimensions{R1}, R)`, for example.
194
+ Overload a method for a new type, especially if you need custom behavior.
195
+ """
180
196
function with_type_parameters (:: Type{<:Dimensions} , :: Type{R} ) where {R}
181
197
return Dimensions{R}
182
198
end
@@ -188,7 +204,7 @@ function with_type_parameters(::Type{<:GenericQuantity}, ::Type{T}, ::Type{D}) w
188
204
end
189
205
190
206
# The following functions should be overloaded for special types
191
- function constructorof (:: Type{T} ) where {T}
207
+ function constructorof (:: Type{T} ) where {T<: Union{AbstractUnionQuantity,AbstractDimensions} }
192
208
return Base. typename (T). wrapper
193
209
end
194
210
function with_type_parameters (:: Type{D} , :: Type{R} ) where {D<: AbstractDimensions ,R}
0 commit comments