| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
- // Exceptions. See /LICENSE for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- package Core library "prelude/copy";
- // Copying an object, which is a conversion from a value representation to an
- // initializing representation.
- interface Copy {
- fn Op[self: Self]() -> Self;
- }
- private fn Bool() -> type = "bool.make_type";
- private fn CharLiteral() -> type = "char_literal.make_type";
- private fn FloatLiteral() -> type = "float_literal.make_type";
- private fn IntLiteral() -> type = "int_literal.make_type";
- impl forall [T:! Copy] const T as Copy {
- fn Op[self: Self]() -> Self { return (self as T).(Copy.Op)() as const T; }
- }
- impl Bool() as Copy {
- fn Op[self: Self]() -> Self = "primitive_copy";
- }
- impl CharLiteral() as Copy {
- fn Op[self: Self]() -> Self = "primitive_copy";
- }
- impl FloatLiteral() as Copy {
- fn Op[self: Self]() -> Self = "primitive_copy";
- }
- impl IntLiteral() as Copy {
- fn Op[self: Self]() -> Self = "primitive_copy";
- }
- impl type as Copy {
- fn Op[self: Self]() -> Self = "primitive_copy";
- }
- impl forall [T:! type] T* as Copy {
- fn Op[self: Self]() -> Self = "primitive_copy";
- }
- // TODO: Implement tuple copy as a variadic generic impl.
- impl () as Copy {
- fn Op[self: Self]() -> Self = "no_op";
- }
- impl forall [T:! Copy] (T,) as Copy {
- fn Op[self: Self]() -> Self {
- return (self.0.Op(),);
- }
- }
- impl forall [T:! Copy, U:! Copy] (T, U) as Copy {
- fn Op[self: Self]() -> Self {
- return (self.0.Op(), self.1.Op());
- }
- }
- impl forall [T:! Copy, U:! Copy, V:! Copy] (T, U, V) as Copy {
- fn Op[self: Self]() -> Self {
- return (self.0.Op(), self.1.Op(), self.2.Op());
- }
- }
|