<html><head></head><body><div>If I needed functionality like this, I would create an enum with a case and associated value for every type I needed.</div><div><br></div><div>enum AnyValue : Equatable {</div><div> case int(Int)</div><div> case string(String)</div><div> // etc</div><div>}<br><br><div class="acompli_signature">Patrick</div><br></div><br><br><br>
<div class="gmail_quote">On Sun, Apr 17, 2016 at 7:13 AM -0700, "Joanna Carter via swift-evolution" <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="3D"ltr"">
<pre>I often find myself needing to construct an instance of a bound generic type at runtime, in much the same manner as I would a "standard" type.
e.g.
As for a standard type…
let aType = Int.Type
let anInt = aType.init(0)
I also want to be able to use the same mechanism for a generic type…
struct MyStruct<t: equatable , etc * />
{
var value: T?
}
let paramType = // type from streaming or reflection compliant with Equatable
let structType = MyStruct<paramtype>.self
let f = structType.init()
At present, the following compiler error is raised…
'paramType' is not a type
I am the only one to require this behaviour? If not, do we want a proposal? If so, could you let me know your views on its worthiness?
Joanna
--
Joanna Carter
Carter Consulting
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
</paramtype></pre>
</div>
</blockquote>
</div>
</body></html>