equality.carbon 867 B

1234567891011121314151617181920212223242526272829
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // NOAUTOUPDATE
  6. package ExplorerTest api;
  7. // TODO: Implement this with some kind of reflection?
  8. impl {.x: i32, .y: i32} as EqWith(Self) {
  9. fn Equal[self: Self](other: Self) -> bool {
  10. return self.x == other.x and self.y == other.y;
  11. }
  12. fn NotEqual[self: Self](other: Self) -> bool {
  13. return self.x != other.x or self.y != other.y;
  14. }
  15. }
  16. fn Main() -> i32 {
  17. var t1: {.x: i32, .y: i32} = {.x = 5, .y = 2};
  18. var t2: {.x: i32, .y: i32} = {.x = 5, .y = 2};
  19. Print("t1 == t2: {0}", if t1 == t2 then 1 else 0);
  20. Print("t1 != t2: {0}", if t1 != t2 then 1 else 0);
  21. return 0;
  22. }
  23. // CHECK:STDOUT: t1 == t2: 1
  24. // CHECK:STDOUT: t1 != t2: 0
  25. // CHECK:STDOUT: result: 0