====== to ====== Der to-Operator beschreibt ein gewünschtes Casting, wenn dies erforderlich ist oder dient zur Dokumentation. to erlaubt eine explizite Umwandlung, auch wenn diese Rechenzeit kostet. Siehe auch [[as]], welcher lediglich als Getter fungiert. (Siehe unten) Point contains int x, y; Startpoint as Point; Endpoint as Point; Color as int; Segment contains Color = (#FFFFFF), // Default Value Startpoint, Endpont; color is Color(#FFFF00); // Hash leitet Hexadezimalzahl ein p1 is Point( 0, 0 ); p2 is Point( 10, 0 ); start is Startpoint( p1 ); end is Endpoint(p2); seg is Segment( color, p1, p2 ); // ok, Ambivalenzhinweis (p1 und p2 könnten verwechselt sein) seg1 is Segment( color, p1 to Startpoint, p2 to Endpoint ); // ok -> Dokumentation seg2 is Segment( p1, p2 ); // fail: Unbekannte Reihenfolge seg3 is Segment( p1 to Startpoint, p2 to Endpoint ); // ok, Color erhält default value seg4 is Segment( p2 to Endpoint, p1 to Startpoint ); // ok, Color erhält default value seg5 is Segment( start, p2 ); // ok, p2 muss Endpoint sein seg6 is Segment( p2, start ); // ok, Ambivalenzwarnung (nicht hint!) seg7 is Segment( p2 to Endpoint, start ); // ok seg8 is Segment( start, end ); // ok seg9 is Segment( end, start ); // ok -> Klare Typzuordnung seg0 is Segment( end to Startpoint, start to Endpoint ); // gewünschtes Casting: end ist ein Point, Startpoint besitzt einen expliziten Point-Konstruktor Siehe auch: [[as]] ===== to als Konvertierung ===== Ziel ist es einen Datentyp in einen anderen zu überführen. Im Idealfall ist der Zieldatensatz bereits vorhanden, in dem Fall funktioniert to wie ein Getter. Hierfür sollte [[as]] implementiert werden. Existiert keine to-Implementiertung, so greift der Compiler auf eine vorhandene as Implementierung zurück. Beispiel: Loop3d contains { points is vector< Point3d >; } SegLoop3d contains { points is vector< SegPoint3d >; Loop3d := { result is vector< Point3d >; for( points ) result.push( value ); return Loop3d( result ); } }