Created
November 24, 2022 13:31
-
-
Save taku0/3ec3d3f137b1aed2a6d2bc3531eafa84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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