Skip to content

Instantly share code, notes, and snippets.

@jepers
Created November 13, 2015 00:56
Show Gist options
  • Save jepers/d498047345230aadeebc to your computer and use it in GitHub Desktop.
Save jepers/d498047345230aadeebc to your computer and use it in GitHub Desktop.
struct True {}
struct False {}
protocol ResultPossessingType {}
extension ResultPossessingType { typealias Result = False }
struct IsIntegerType<T> : ResultPossessingType {
static func printResult() { print("Static method prints \(self).Result:", Result.self, self.Result.self) } // <-- Added self.Result.self
}
extension IsIntegerType where T: IntegerType {
typealias Result = True
}
typealias A = IsIntegerType<Float> // NOTE: Float is NOT an IntegerType, so A.Result == False, right?
typealias B = IsIntegerType<Int32> // NOTE: Int32 is an IntegerType, so B.Result == True, right?
print("Global scope prints \(A.self).Result:", A.Result.self)
print("Global scope prints \(B.self).Result:", B.Result.self)
A.printResult()
B.printResult()
// Output
// Global scope prints IsIntegerType<Float>.Result: False
// Global scope prints IsIntegerType<Int32>.Result: True
// Static method prints IsIntegerType<Float>.Result: True False
// Static method prints IsIntegerType<Int32>.Result: True False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment