type(of:) is the Swift 3 spelling of what was known in Swift 2 as dynamicType.<br><div class="gmail_quote"><div dir="ltr">On Wed, Feb 8, 2017 at 14:09 Daryle Walker via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg">I’ve been trying to get the maximum of a list of counts. I started by using “myCollection.map { $0.myCountProperty }.reduce(0, max)”. Then I thought I should really use the value closest to negative infinity as the base. The problem is how to get that value. The current hard-coded “0” works because the count type ultimately aliases “Int”, but shouldn’t have to count on that. I put in “MyCountType.min”, where “MyCountType” is hard coded from the docs of “myCountProperty”, but I shouldn’t have to do that either.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">There is a “type(of:)” global function, which I did use. But not only did I have to make up an expression to go in there, its return value, some sort of meta-type stuff I don’t understand, can’t be used on the right side of a “typealias” construct. I ultimately used “let lowestCount = type(of: anElement.myCountProperty).min” to get what I needed.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Some queries/requests:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">1. Is the expression within “type(of:)” evaluated?</div><div class="gmail_msg">2. I think we need the equivalent of "std::declval” from C++. Especially if the answer to (1) is yes.</div><div class="gmail_msg">3. Why isn’t the return type(?) of “type(of:)” compile-time enough to be used as a type-alias?</div><div class="gmail_msg">4. Should we add something like the C++ type-traits collection of generic structures to give use type information as type-aliases or type-level instances?</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word" class="gmail_msg"><div class="gmail_msg">— </div><div class="gmail_msg">Daryle Walker<br class="gmail_msg">Mac, Internet, and Video Game Junkie<br class="gmail_msg">darylew AT mac DOT com </div></div>
</div>
<br class="gmail_msg"></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>