mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
There's still work left to do. In terms of next steps, there's still rdar://problem/22126141, which covers removing the 'workaround' overloads for print (that prevent bogus overload resolution failures), as well as providing a decent diagnostic when users invoke print with 'appendNewline'. Swift SVN r30976
56 lines
1.1 KiB
Swift
56 lines
1.1 KiB
Swift
// RUN: rm -rf %t && mkdir %t
|
|
// RUN: %target-build-swift %s -o %t/a.out
|
|
// RUN: %target-run %t/a.out | FileCheck %s
|
|
// REQUIRES: executable_test
|
|
|
|
protocol MyPrintable {
|
|
func myPrint()
|
|
}
|
|
|
|
extension Int : MyPrintable {
|
|
func myPrint() {
|
|
print(self.description, terminator: "")
|
|
}
|
|
}
|
|
|
|
extension String : MyPrintable {
|
|
func myPrint() {
|
|
print(self.debugDescription, terminator: "")
|
|
}
|
|
}
|
|
|
|
struct BufferedPair<T, U> {
|
|
var front: UInt8
|
|
var first: T
|
|
var second: U
|
|
var back: UInt8
|
|
}
|
|
|
|
enum State : MyPrintable {
|
|
case CA, OR, WA
|
|
|
|
func myPrint() {
|
|
switch self {
|
|
case .CA:
|
|
print("California", terminator: "")
|
|
case .OR:
|
|
print("Oregon", terminator: "")
|
|
case .WA:
|
|
print("Washington", terminator: "")
|
|
}
|
|
}
|
|
}
|
|
|
|
func printPair<A : MyPrintable, B : MyPrintable>(p: BufferedPair<A,B>) {
|
|
print("\(p.front) ", terminator: "")
|
|
p.first.myPrint()
|
|
print(" ", terminator: "")
|
|
p.second.myPrint()
|
|
print(" \(p.back)")
|
|
}
|
|
|
|
var p = BufferedPair(front: 219, first: State.OR, second: "Idaho's Portugal",
|
|
back: 17)
|
|
// CHECK: 219 Oregon "Idaho\'s Portugal" 17
|
|
printPair(p)
|