implement ConstructionBase interface #1086
Open
+40
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Brief motivation: ConstructionBase is the foundational package for (re)constructing and modifying immutable and mutable objects, see https://github.com/JuliaObjects/ConstructionBase.jl.
constructorof(T)(args)
is the main interface of that package, it works with lots of types by default. However, it needs to be overloaded when some type parameters cannot be determined purely from arguments passed to the constructor. Clearly, this is the case forSArray
.This PR implements that interface, making StaticArrays immediately compatible with all those packages and user codes that use ConstructionBase.
A similar PR was proposed 1.5 years ago: #901. See for more discussion and more details on the motivation.
Several things have changed since that PR that make me believe there are more reasons for this to be accepted now.
First, the implementation here is definitely cleaner and shorter than in #901. It just forwards
constructorof
to already existing S/MArray constructors, keeping only those type parameters that are necessary for reconstruction. So, it automatically supports all S/MArray constructor variations.In partucular, this addresses a concern made for #901:
Second, more and more packages are using ConstructionBase: already more than 1k in General (transitively) depend on it, and this number is growing. ConstructionBase has stayed stable and there are no plans for breaking changes or "feature creep". It's an extremely lightweight package with no dependencies and negligible load time.
@rafaqz @jw3126 @andyferris