I was reading the document and was wondering if it might make sense to look
into using definitions rather than conventions:
public protocol LiteralCreatable {
associatedtype LiteralType
init(literalValue : LiteralType)
}
public protocol NilLiteralConvertible : LiteralCreatable {
associatedtype LiteralType = ()
}
public protocol StringLiteralCreatable : LiteralCreatable {
associatedtype LiteralType = String
}
public protocol IntLiteralCreatable : LiteralCreatable {
associatedtype LiteralType = Int
}
…
which leads to the following code:
struct TT { }
extension TT: IntLiteralCreatable {
init(literalValue: Int) { }
}
extension TT: StringLiteralCreatable {
init(literalValue: String) { }
}
let tt1 = TT()
let tt2 = TT(literalValue: 20)
let tt3 = TT(literalValue: "StringLiteral")
…
or even this:
struct XX { }
extension XX: IntLiteralCreatable, StringLiteralCreatable {
init(literalValue: Int) { }
init(literalValue: String) { }
}
let xx1 = XX()
let xx2 = XX(literalValue: 20)
let xx3 = XX(literalValue: "StringLiteral")
cheers
LM/_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution