It's a bit hacky but using the `Type.init()` convention it's possible:
    
    
    import std/typetraits
    type Foo[T] = object
      val: T
    
    proc init*[T: Foo](_: typedesc[T]): auto =
      when Foo is T:
        Foo[int]()
      else:
        T()
    
    assert Foo.init() is Foo[int]
    assert Foo[string].init() is Foo[string]
    
    
    Run

Reply via email to