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