[swift-users] Type alias with a "where" clause specifying required associated type

Rudolf Adamkovič salutis at me.com
Mon Sep 4 18:11:50 CDT 2017

I have the following ProceduralDrawing type:

public struct ProceduralDrawing<Float, Point: PointType> where Point.Float == Float {
    // ... code that used Float and Point ...

public protocol PointType {
    associatedtype Float: FloatingPoint
    var x: Float { get }
    var y: Float { get }

I would like to avoid adding Point as a generic parameter but the following doesn’t work:

public struct ProceduralDrawing<Float: FloatingPoint> {
    // ERROR: 'where' clause cannot be attached to a non-generic declaration
    typealias Point = PointType where Point.Float == Float
    // ... code that uses Float and Point ...

Is there a way to do this? If not, why?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170905/468c87b1/attachment.html>

More information about the swift-users mailing list