1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
12 #include "test_macros.h"
13 #include <type_traits>
19 TEST_CONSTEXPR
Rep() : data_(-1) {}
20 explicit TEST_CONSTEXPR
Rep(int i
) : data_(i
) {}
22 bool TEST_CONSTEXPR
operator==(int i
) const {return data_
== i
;}
23 bool TEST_CONSTEXPR
operator==(const Rep
& r
) const {return data_
== r
.data_
;}
25 Rep
& operator*=(Rep x
) {data_
*= x
.data_
; return *this;}
26 Rep
& operator/=(Rep x
) {data_
/= x
.data_
; return *this;}
33 #if TEST_STD_VER >= 11
34 // Several duration operators take a Rep parameter. Before LWG3050 this
35 // parameter was constrained to be convertible from a non-const object,
36 // but the code always uses a const object. So the function was SFINAE'd
37 // away for this type. LWG3050 fixes the constraint to use a const
39 struct RepConstConvertibleLWG3050
{
40 operator long() = delete;
41 operator long() const { return 2; }
45 struct std::common_type
<RepConstConvertibleLWG3050
, int> {
49 struct std::common_type
<int, RepConstConvertibleLWG3050
> {
53 #endif // TEST_STD_VER >= 11
55 // std::chrono:::duration has only '*', '/' and '%' taking a "Rep" parameter
57 // Multiplication is commutative, division is not.
58 template <class Rep
, class Period
>
59 std::chrono::duration
<Rep
, Period
>
60 operator*(std::chrono::duration
<Rep
, Period
> d
, NotARep
) { return d
; }
62 template <class Rep
, class Period
>
63 std::chrono::duration
<Rep
, Period
>
64 operator*(NotARep
, std::chrono::duration
<Rep
, Period
> d
) { return d
; }
66 template <class Rep
, class Period
>
67 std::chrono::duration
<Rep
, Period
>
68 operator/(std::chrono::duration
<Rep
, Period
> d
, NotARep
) { return d
; }
70 template <class Rep
, class Period
>
71 std::chrono::duration
<Rep
, Period
>
72 operator%(std::chrono::duration
<Rep
, Period
> d
, NotARep
) { return d
; }
74 // op= is not commutative.
75 template <class Rep
, class Period
>
76 std::chrono::duration
<Rep
, Period
>&
77 operator*=(std::chrono::duration
<Rep
, Period
>& d
, NotARep
) { return d
; }
79 template <class Rep
, class Period
>
80 std::chrono::duration
<Rep
, Period
>&
81 operator/=(std::chrono::duration
<Rep
, Period
>& d
, NotARep
) { return d
; }
83 template <class Rep
, class Period
>
84 std::chrono::duration
<Rep
, Period
>&
85 operator%=(std::chrono::duration
<Rep
, Period
>& d
, NotARep
) { return d
; }