1 //===- llvm/unittest/ADT/CountCopyAndMove.h - Optional unit tests ---------===//
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_UNITTESTS_ADT_COUNTCOPYANDMOVE_H
10 #define LLVM_UNITTESTS_ADT_COUNTCOPYANDMOVE_H
14 struct CountCopyAndMove
{
15 static int DefaultConstructions
;
16 static int ValueConstructions
;
17 static int CopyConstructions
;
18 static int CopyAssignments
;
19 static int MoveConstructions
;
20 static int MoveAssignments
;
21 static int Destructions
;
24 CountCopyAndMove() { ++DefaultConstructions
; }
25 explicit CountCopyAndMove(int val
) : val(val
) { ++ValueConstructions
; }
26 CountCopyAndMove(const CountCopyAndMove
&other
) : val(other
.val
) {
29 CountCopyAndMove
&operator=(const CountCopyAndMove
&other
) {
34 CountCopyAndMove(CountCopyAndMove
&&other
) : val(other
.val
) {
37 CountCopyAndMove
&operator=(CountCopyAndMove
&&other
) {
42 ~CountCopyAndMove() { ++Destructions
; }
44 static void ResetCounts() {
45 DefaultConstructions
= 0;
46 ValueConstructions
= 0;
47 CopyConstructions
= 0;
49 MoveConstructions
= 0;
54 static int TotalConstructions() {
55 return DefaultConstructions
+ ValueConstructions
+ MoveConstructions
+
59 static int TotalCopies() { return CopyConstructions
+ CopyAssignments
; }
61 static int TotalMoves() { return MoveConstructions
+ MoveAssignments
; }
64 } // end namespace llvm
66 #endif // LLVM_UNITTESTS_ADT_COUNTCOPYANDMOVE_H