67 lines · c
1//===- llvm/unittest/ADT/CountCopyAndMove.h - Optional unit tests ---------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_UNITTESTS_ADT_COUNTCOPYANDMOVE_H10#define LLVM_UNITTESTS_ADT_COUNTCOPYANDMOVE_H11 12namespace llvm {13 14struct 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;22 int val;23 24 CountCopyAndMove() { ++DefaultConstructions; }25 explicit CountCopyAndMove(int val) : val(val) { ++ValueConstructions; }26 CountCopyAndMove(const CountCopyAndMove &other) : val(other.val) {27 ++CopyConstructions;28 }29 CountCopyAndMove &operator=(const CountCopyAndMove &other) {30 val = other.val;31 ++CopyAssignments;32 return *this;33 }34 CountCopyAndMove(CountCopyAndMove &&other) : val(other.val) {35 ++MoveConstructions;36 }37 CountCopyAndMove &operator=(CountCopyAndMove &&other) {38 val = other.val;39 ++MoveAssignments;40 return *this;41 }42 ~CountCopyAndMove() { ++Destructions; }43 44 static void ResetCounts() {45 DefaultConstructions = 0;46 ValueConstructions = 0;47 CopyConstructions = 0;48 CopyAssignments = 0;49 MoveConstructions = 0;50 MoveAssignments = 0;51 Destructions = 0;52 }53 54 static int TotalConstructions() {55 return DefaultConstructions + ValueConstructions + MoveConstructions +56 CopyConstructions;57 }58 59 static int TotalCopies() { return CopyConstructions + CopyAssignments; }60 61 static int TotalMoves() { return MoveConstructions + MoveAssignments; }62};63 64} // end namespace llvm65 66#endif // LLVM_UNITTESTS_ADT_COUNTCOPYANDMOVE_H67