Skip to content

Instantly share code, notes, and snippets.

@taku0
Created November 24, 2022 13:31
Show Gist options
  • Save taku0/3ec3d3f137b1aed2a6d2bc3531eafa84 to your computer and use it in GitHub Desktop.
Save taku0/3ec3d3f137b1aed2a6d2bc3531eafa84 to your computer and use it in GitHub Desktop.
protocol P {
func aaa() -> Int
}
class Foo: P {
func aaa() -> Int {
return 1
}
}
class Bar: P {
var a = 1
func aaa() -> Int {
return 2
}
}
@inline(never)
func foo(x: some P, y: some P) -> Int {
var a = 1000000 + x.aaa() + y.aaa()
while a > 1 {
a /= 3
}
if (a == 0) {
return x.aaa()
} else {
return y.aaa()
}
}
@inline(never)
func bar<A: P, B: P>(x: A, y: B) -> Int {
var a = 1000000 + x.aaa() + y.aaa()
while a > 1 {
a /= 3
}
if (a == 0) {
return x.aaa()
} else {
return y.aaa()
}
}
print(foo(x: Foo(), y: Foo()))
print(foo(x: Foo(), y: Bar()))
print(foo(x: Bar(), y: Foo()))
print(foo(x: Bar(), y: Bar()))
print(bar(x: Foo(), y: Foo()))
print(bar(x: Foo(), y: Bar()))
print(bar(x: Bar(), y: Foo()))
print(bar(x: Bar(), y: Bar()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment