rep.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 REP_H
  9. #define REP_H
  10. #include "test_macros.h"
  11. class Rep
  12. {
  13. int data_;
  14. public:
  15. TEST_CONSTEXPR Rep() : data_(-1) {}
  16. explicit TEST_CONSTEXPR Rep(int i) : data_(i) {}
  17. bool TEST_CONSTEXPR operator==(int i) const {return data_ == i;}
  18. bool TEST_CONSTEXPR operator==(const Rep& r) const {return data_ == r.data_;}
  19. Rep& operator*=(Rep x) {data_ *= x.data_; return *this;}
  20. Rep& operator/=(Rep x) {data_ /= x.data_; return *this;}
  21. };
  22. // This is PR#41130
  23. struct NotARep {};
  24. // std::chrono:::duration has only '*', '/' and '%' taking a "Rep" parameter
  25. // Multiplication is commutative, division is not.
  26. template <class Rep, class Period>
  27. std::chrono::duration<Rep, Period>
  28. operator*(std::chrono::duration<Rep, Period> d, NotARep) { return d; }
  29. template <class Rep, class Period>
  30. std::chrono::duration<Rep, Period>
  31. operator*(NotARep, std::chrono::duration<Rep, Period> d) { return d; }
  32. template <class Rep, class Period>
  33. std::chrono::duration<Rep, Period>
  34. operator/(std::chrono::duration<Rep, Period> d, NotARep) { return d; }
  35. template <class Rep, class Period>
  36. std::chrono::duration<Rep, Period>
  37. operator%(std::chrono::duration<Rep, Period> d, NotARep) { return d; }
  38. // op= is not commutative.
  39. template <class Rep, class Period>
  40. std::chrono::duration<Rep, Period>&
  41. operator*=(std::chrono::duration<Rep, Period>& d, NotARep) { return d; }
  42. template <class Rep, class Period>
  43. std::chrono::duration<Rep, Period>&
  44. operator/=(std::chrono::duration<Rep, Period>& d, NotARep) { return d; }
  45. template <class Rep, class Period>
  46. std::chrono::duration<Rep, Period>&
  47. operator%=(std::chrono::duration<Rep, Period>& d, NotARep) { return d; }
  48. #endif // REP_H