[flang][runtime] Make defined formatted I/O process format elementally (#74150)
[llvm-project.git] / libcxx / test / support / Counter.h
blob6a51cc991eee70ba3a089c42186f2615f8eaccb9
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 COUNTER_H
10 #define COUNTER_H
12 #include <functional> // for std::hash
14 #include "test_macros.h"
16 struct Counter_base { static int gConstructed; };
18 template <typename T>
19 class Counter : public Counter_base
21 public:
22 Counter() : data_() { ++gConstructed; }
23 Counter(const T &data) : data_(data) { ++gConstructed; }
24 Counter(const Counter& rhs) : data_(rhs.data_) { ++gConstructed; }
25 Counter& operator=(const Counter& rhs) { data_ = rhs.data_; return *this; }
26 #if TEST_STD_VER >= 11
27 Counter(Counter&& rhs) : data_(std::move(rhs.data_)) { ++gConstructed; }
28 Counter& operator=(Counter&& rhs) { data_ = std::move(rhs.data_); return *this; }
29 #endif
30 ~Counter() { --gConstructed; }
32 const T& get() const {return data_;}
34 bool operator==(const Counter& x) const {return data_ == x.data_;}
35 bool operator< (const Counter& x) const {return data_ < x.data_;}
37 private:
38 T data_;
41 int Counter_base::gConstructed = 0;
43 namespace std {
45 template <class T>
46 struct hash<Counter<T> >
48 typedef Counter<T> argument_type;
49 typedef std::size_t result_type;
51 std::size_t operator()(const Counter<T>& x) const {return std::hash<T>()(x.get());}
55 #endif