DefaultOnly.h 943 B

12345678910111213141516171819202122232425262728293031323334
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef DEFAULTONLY_H
  9. #define DEFAULTONLY_H
  10. #include <cassert>
  11. class DefaultOnly
  12. {
  13. int data_;
  14. DefaultOnly(const DefaultOnly&);
  15. DefaultOnly& operator=(const DefaultOnly&);
  16. public:
  17. static int count;
  18. DefaultOnly() : data_(-1) {++count;}
  19. ~DefaultOnly() {data_ = 0; --count;}
  20. friend bool operator==(const DefaultOnly& x, const DefaultOnly& y)
  21. {return x.data_ == y.data_;}
  22. friend bool operator< (const DefaultOnly& x, const DefaultOnly& y)
  23. {return x.data_ < y.data_;}
  24. };
  25. int DefaultOnly::count = 0;
  26. #endif // DEFAULTONLY_H