Can this be done with an outer constructor?

This is how it is handled by the docs. Basically you have to suppress the default constructors somehow…


struct AA{T} 
    a::T
    function AA(a::T) where T
        new{T}(a)
    end
end
# Create a new wrapper of same inner type
AA{T}(a...) where T = AA(T(a...))

# Dummy to wrap
struct AAA
    a
end

julia> aa = AA(AAA(3))
AA{AAA}(AAA(3))

julia> at = typeof(aa)
AA{AAA}

julia> at(5)
AA{AAA}(AAA(5))
2 Likes