File indexing completed on 2025-01-30 09:31:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef ABSL_CONTAINER_INTERNAL_TRACKED_H_
0016 #define ABSL_CONTAINER_INTERNAL_TRACKED_H_
0017
0018 #include <stddef.h>
0019
0020 #include <memory>
0021 #include <utility>
0022
0023 #include "absl/base/config.h"
0024
0025 namespace absl {
0026 ABSL_NAMESPACE_BEGIN
0027 namespace container_internal {
0028
0029
0030 template <class T>
0031 class Tracked {
0032 public:
0033 Tracked() {}
0034
0035 Tracked(const T& val) : val_(val) {}
0036 Tracked(const Tracked& that)
0037 : val_(that.val_),
0038 num_moves_(that.num_moves_),
0039 num_copies_(that.num_copies_) {
0040 ++(*num_copies_);
0041 }
0042 Tracked(Tracked&& that)
0043 : val_(std::move(that.val_)),
0044 num_moves_(std::move(that.num_moves_)),
0045 num_copies_(std::move(that.num_copies_)) {
0046 ++(*num_moves_);
0047 }
0048 Tracked& operator=(const Tracked& that) {
0049 val_ = that.val_;
0050 num_moves_ = that.num_moves_;
0051 num_copies_ = that.num_copies_;
0052 ++(*num_copies_);
0053 }
0054 Tracked& operator=(Tracked&& that) {
0055 val_ = std::move(that.val_);
0056 num_moves_ = std::move(that.num_moves_);
0057 num_copies_ = std::move(that.num_copies_);
0058 ++(*num_moves_);
0059 }
0060
0061 const T& val() const { return val_; }
0062
0063 friend bool operator==(const Tracked& a, const Tracked& b) {
0064 return a.val_ == b.val_;
0065 }
0066 friend bool operator!=(const Tracked& a, const Tracked& b) {
0067 return !(a == b);
0068 }
0069
0070 size_t num_copies() { return *num_copies_; }
0071 size_t num_moves() { return *num_moves_; }
0072
0073 private:
0074 T val_;
0075 std::shared_ptr<size_t> num_moves_ = std::make_shared<size_t>(0);
0076 std::shared_ptr<size_t> num_copies_ = std::make_shared<size_t>(0);
0077 };
0078
0079 }
0080 ABSL_NAMESPACE_END
0081 }
0082
0083 #endif