## std.clone: Classes for explicitly Clonable types. ## This module is imported by default. ## The Clone class. Any type implementing Clone is cloneable. ## Data structures built with pointers and references are pretty much ## the only things that are *not* implicitly clonable. pub type Clone = class clone(lent Self): Self ## Generic implementation of `clone` for structs. ## fixme: this relies on no component of a struct being a ref or ptr ## cloning an rc is fine?? pub func clone[T: Clone](self: struct[T]): struct[T] = ... ## Generic implementation of `clone` for tuples. pub func clone[T: Clone](self: tuple[T]): tuple[T] = ... ## Implementation of `clone` for arrays of any size. pub func clone[T: Clone, size: const uint](self: array[T, size]): array[T, size] = var res: array[T, size] for i in 0 .. size do res.push(self.i.clone) ## Implementation of `clone` for lists. pub func clone[T: Clone](self: list[T]): list[T] = var res: list[T] for elem in self do res.push(elem.clone) # the explicit dependency on Clone gives us this ## Implementation of `clone` for strings. pub func clone(self: str): str = var res: str for char in self do res.push(char)