168716573Sc8ef //===- llvm/unittest/ADT/CountCopyAndMove.h - Optional unit tests ---------===// 268716573Sc8ef // 368716573Sc8ef // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 468716573Sc8ef // See https://llvm.org/LICENSE.txt for license information. 568716573Sc8ef // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 668716573Sc8ef // 768716573Sc8ef //===----------------------------------------------------------------------===// 868716573Sc8ef 968716573Sc8ef #ifndef LLVM_UNITTESTS_ADT_COUNTCOPYANDMOVE_H 1068716573Sc8ef #define LLVM_UNITTESTS_ADT_COUNTCOPYANDMOVE_H 1168716573Sc8ef 1268716573Sc8ef namespace llvm { 1368716573Sc8ef 1468716573Sc8ef struct CountCopyAndMove { 15*e8ca306fSDmitry Yanovsky static int DefaultConstructions; 16*e8ca306fSDmitry Yanovsky static int ValueConstructions; 1768716573Sc8ef static int CopyConstructions; 1868716573Sc8ef static int CopyAssignments; 1968716573Sc8ef static int MoveConstructions; 2068716573Sc8ef static int MoveAssignments; 2168716573Sc8ef static int Destructions; 2268716573Sc8ef int val; 2368716573Sc8ef 24*e8ca306fSDmitry Yanovsky CountCopyAndMove() { ++DefaultConstructions; } 25*e8ca306fSDmitry Yanovsky explicit CountCopyAndMove(int val) : val(val) { ++ValueConstructions; } 2668716573Sc8ef CountCopyAndMove(const CountCopyAndMove &other) : val(other.val) { 2768716573Sc8ef ++CopyConstructions; 2868716573Sc8ef } 2968716573Sc8ef CountCopyAndMove &operator=(const CountCopyAndMove &other) { 3068716573Sc8ef val = other.val; 3168716573Sc8ef ++CopyAssignments; 3268716573Sc8ef return *this; 3368716573Sc8ef } 3468716573Sc8ef CountCopyAndMove(CountCopyAndMove &&other) : val(other.val) { 3568716573Sc8ef ++MoveConstructions; 3668716573Sc8ef } 3768716573Sc8ef CountCopyAndMove &operator=(CountCopyAndMove &&other) { 3868716573Sc8ef val = other.val; 3968716573Sc8ef ++MoveAssignments; 4068716573Sc8ef return *this; 4168716573Sc8ef } 4268716573Sc8ef ~CountCopyAndMove() { ++Destructions; } 4368716573Sc8ef 4468716573Sc8ef static void ResetCounts() { 45*e8ca306fSDmitry Yanovsky DefaultConstructions = 0; 46*e8ca306fSDmitry Yanovsky ValueConstructions = 0; 4768716573Sc8ef CopyConstructions = 0; 4868716573Sc8ef CopyAssignments = 0; 4968716573Sc8ef MoveConstructions = 0; 5068716573Sc8ef MoveAssignments = 0; 5168716573Sc8ef Destructions = 0; 5268716573Sc8ef } 5368716573Sc8ef 54*e8ca306fSDmitry Yanovsky static int TotalConstructions() { 55*e8ca306fSDmitry Yanovsky return DefaultConstructions + ValueConstructions + MoveConstructions + 56*e8ca306fSDmitry Yanovsky CopyConstructions; 57*e8ca306fSDmitry Yanovsky } 58*e8ca306fSDmitry Yanovsky 5968716573Sc8ef static int TotalCopies() { return CopyConstructions + CopyAssignments; } 6068716573Sc8ef 6168716573Sc8ef static int TotalMoves() { return MoveConstructions + MoveAssignments; } 6268716573Sc8ef }; 6368716573Sc8ef 6468716573Sc8ef } // end namespace llvm 6568716573Sc8ef 6668716573Sc8ef #endif // LLVM_UNITTESTS_ADT_COUNTCOPYANDMOVE_H 67