custom_equality.carbon 813 B

1234567891011121314151617181920212223242526272829303132
  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. // AUTOUPDATE
  6. package ExplorerTest api;
  7. class MyType {
  8. var value: i32;
  9. extend impl as EqWith(Self) {
  10. fn Equal[self: Self](other: Self) -> bool {
  11. return self.value == other.value;
  12. }
  13. fn NotEqual[self: Self](other: Self) -> bool{
  14. return self.value != other.value;
  15. }
  16. }
  17. }
  18. fn Main() -> i32 {
  19. let x: MyType = {.value = 1};
  20. let y: MyType = {.value = 2};
  21. Print("structs equal: {0}", if x == y then 1 else 0);
  22. Print("structs not equal: {0}", if x != y then 1 else 0);
  23. return 0;
  24. }
  25. // CHECK:STDOUT: structs equal: 0
  26. // CHECK:STDOUT: structs not equal: 1
  27. // CHECK:STDOUT: result: 0