Coming from C++, I'm trying to do some metaprogramming in Swift. For example, I'd like to implement a metafunction that adds two numbers. I've tried something like this:
protocol IntWrapper {
class var value: Int { get }
}
struct A: IntWrapper {
static let value = 5
}
struct B: IntWrapper {
static let value = 7
}
struct Sum<T: IntWrapper, U: IntWrapper>: IntWrapper {
static let value = T.value + U.value
}
This, however, doesn't work: Xcode complains that T.Type
doesn't have a member value
(or just crashes, sometimes.)
How can implement such functionality?