Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / time / rep.h
blob6df3e7ad27c4da2e872f921c1cb5bd51f11ebf7c
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 //===----------------------------------------------------------------------===//
9 #ifndef REP_H
10 #define REP_H
12 #include "test_macros.h"
13 #include <type_traits>
15 class Rep
17 int data_;
18 public:
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;}
29 // This is PR#41130
31 struct NotARep {};
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
38 // object.
39 struct RepConstConvertibleLWG3050 {
40 operator long() = delete;
41 operator long() const { return 2; }
44 template <>
45 struct std::common_type<RepConstConvertibleLWG3050, int> {
46 using type = long;
48 template <>
49 struct std::common_type<int, RepConstConvertibleLWG3050> {
50 using type = long;
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; }
87 #endif // REP_H