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 CopyConstructions
;
16 static int CopyAssignments
;
17 static int MoveConstructions
;
18 static int MoveAssignments
;
19 static int Destructions
;
22 CountCopyAndMove() = default;
23 explicit CountCopyAndMove(int val
) : val(val
) {}
24 CountCopyAndMove(const CountCopyAndMove
&other
) : val(other
.val
) {
27 CountCopyAndMove
&operator=(const CountCopyAndMove
&other
) {
32 CountCopyAndMove(CountCopyAndMove
&&other
) : val(other
.val
) {
35 CountCopyAndMove
&operator=(CountCopyAndMove
&&other
) {
40 ~CountCopyAndMove() { ++Destructions
; }
42 static void ResetCounts() {
43 CopyConstructions
= 0;
45 MoveConstructions
= 0;
50 static int TotalCopies() { return CopyConstructions
+ CopyAssignments
; }
52 static int TotalMoves() { return MoveConstructions
+ MoveAssignments
; }
55 } // end namespace llvm
57 #endif // LLVM_UNITTESTS_ADT_COUNTCOPYANDMOVE_H