Description
openedon Jun 26, 2016
The function similar
accepts a container as first parameter, but not a container type, in the same way as e.g. eltype
. (If dims
is not specified, it should then construct an empty container.)
In some cases, for example in distributed computing, one wants to allocate a container to hold the result of a map
-like calculation, without having access to the original container. However, the type of the original container is known, as well as the element type of the result. In this case, the interface offered by similar
is insufficient -- it does not allow allocating a new container without creating an empty dummy container from the type.
A fall-back definition that could be added to Base is
similar{CT}(::Type{CT}, specs...) = similar(CT(), specs...)
although I assume that many container types will want to provide a more specialized version that avoid creating an empty container.