Einzelnen Beitrag anzeigen

Robert_G
(Gast)

n/a Beiträge
 
#31

Re: Delphigeschädigter Möchtegerncoder alleine mit VC++...

  Alt 14. Jul 2005, 00:52
Das heißt zwar in .Net nun generics anstatt Templates, aber es ist ungemein zeitsparend.

Code:
public class Miep<T>
    where T : IComparable
{
    T value;

    public T Value
    {
        get{return this.value;}
        set{this.value = value;}
    }

    public static bool operator <(Miep<T> left, Miep<T> right)
    {
        return left.Value.CompareTo(right.Value) < 0;
    }

    public static bool operator >(Miep<T> left, Miep<T> right)
    {
        return left.Value.CompareTo(right.Value) > 0;
    }
}
Delphi-Quellcode:
type
   Miep<T> = public class
      where T is IComparable;
   public
      property Value : T;
      class operator Less(left, right: Miep<T>) : boolean;
      class operator Greater(left, right: Miep<T>) : boolean;
  end;
  
implementation

class operator Miep<T>.Less(left: Miep<T>; right: Miep<T>) : boolean;
begin
   exit (left.Value.CompareTo(right.Value) < 0);
end;

class operator Miep<T>.Greater(left, right: Miep<T>) : boolean;
begin
   exit (left.Value.CompareTo(right.Value) > 0);
end;
  Mit Zitat antworten Zitat