Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Parametric constructor, promotion and splatting (...)

$
0
0

Hi there,

I am reading the page ParametricConstructors of the manual, where a struct Point is defined as:

struct Point{T<:Real}
           x::T
           y::T
           Point{T}(x,y) where {T<:Real} = new(x,y)
       end

and then the following constructor is presented:

Point(x::Real, y::Real) = Point(promote(x,y)...)

I am particularly intrigued with the use of the splatting operator (…) rigtht after the promote(x,y) call. In this very same example it seems unnecessary, since there are exactly two arguments for Point in the left-hand side as well for promote in the right-hand side. Is this really the case here? If so, I wonder about a specific example, in another context, where the use of the splatting operator would make sense or, perhaps, be unavoidable.

Thanks

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles