Skip to content

Commit

Permalink
Add docstring to promote_op (#25689)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters authored Jan 25, 2018
1 parent 60c7a4c commit a101ef4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions base/promotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,22 @@ else
_return_type(@nospecialize(f), @nospecialize(t)) = Any
end

"""
promote_op(f, argtypes...)
Guess what an appropriate container eltype would be for storing results of
`f(::argtypes...)`. The guess is in part based on type inference, so can change any time.
!!! warning
In pathological cases, the type returned by `promote_op(f, argtypes...)` may not even
be a supertype of the return value of `f(::argtypes...)`. Therefore, `promote_op`
should _not_ be used e.g. in the preallocation of an output array.
!!! warning
Due to its fragility, use of `promote_op` should be avoided. It is preferable to base
the container eltype on the type of the actual elements. Only in the absence of any
elements (for an empty result container), it may be unavoidable to call `promote_op`.
"""
promote_op(::Any...) = (@_inline_meta; Any)
function promote_op(f, ::Type{S}) where S
@_inline_meta
Expand Down

0 comments on commit a101ef4

Please sign in to comment.