Skip to content

Conversation

@rfourquet
Copy link
Member

This makes it more convenient for simple types to use the make mechanism. E.g.:

struct A
    a::Int
end

rand(rng::AbstractRNG, sp::SamplerTrivial{<:Make{A}}) = A(rand(rng, 1:sp[].x))

rand(make(A, 9)) # => A(3)

@rfourquet
Copy link
Member Author

Note that this defers errors (e.g. MethodError) from a make call to a rand call, i.e. make(Matrix, 3) doesn't throw anymore (not that this couldn't be made to throw...), but rand(make(Matrix, 3)) does.

@rfourquet rfourquet changed the title maketype default maketype(T, ...) defaults to T Jul 15, 2019
@rfourquet rfourquet merged commit 7e966c0 into master Jul 15, 2019
@rfourquet rfourquet deleted the maketype-default branch July 15, 2019 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant