bloaty/third_party/abseil-cpp/absl/container/internal/tracked.h
Go to the documentation of this file.
1 // Copyright 2018 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ABSL_CONTAINER_INTERNAL_TRACKED_H_
16 #define ABSL_CONTAINER_INTERNAL_TRACKED_H_
17 
18 #include <stddef.h>
19 
20 #include <memory>
21 #include <utility>
22 
23 #include "absl/base/config.h"
24 
25 namespace absl {
27 namespace container_internal {
28 
29 // A class that tracks its copies and moves so that it can be queried in tests.
30 template <class T>
31 class Tracked {
32  public:
33  Tracked() {}
34  // NOLINTNEXTLINE(runtime/explicit)
35  Tracked(const T& val) : val_(val) {}
36  Tracked(const Tracked& that)
37  : val_(that.val_),
38  num_moves_(that.num_moves_),
39  num_copies_(that.num_copies_) {
40  ++(*num_copies_);
41  }
42  Tracked(Tracked&& that)
43  : val_(std::move(that.val_)),
44  num_moves_(std::move(that.num_moves_)),
46  ++(*num_moves_);
47  }
48  Tracked& operator=(const Tracked& that) {
49  val_ = that.val_;
50  num_moves_ = that.num_moves_;
51  num_copies_ = that.num_copies_;
52  ++(*num_copies_);
53  }
55  val_ = std::move(that.val_);
56  num_moves_ = std::move(that.num_moves_);
57  num_copies_ = std::move(that.num_copies_);
58  ++(*num_moves_);
59  }
60 
61  const T& val() const { return val_; }
62 
63  friend bool operator==(const Tracked& a, const Tracked& b) {
64  return a.val_ == b.val_;
65  }
66  friend bool operator!=(const Tracked& a, const Tracked& b) {
67  return !(a == b);
68  }
69 
70  size_t num_copies() { return *num_copies_; }
71  size_t num_moves() { return *num_moves_; }
72 
73  private:
74  T val_;
75  std::shared_ptr<size_t> num_moves_ = std::make_shared<size_t>(0);
76  std::shared_ptr<size_t> num_copies_ = std::make_shared<size_t>(0);
77 };
78 
79 } // namespace container_internal
81 } // namespace absl
82 
83 #endif // ABSL_CONTAINER_INTERNAL_TRACKED_H_
absl::container_internal::Tracked::Tracked
Tracked(const Tracked &that)
Definition: bloaty/third_party/abseil-cpp/absl/container/internal/tracked.h:36
absl::container_internal::Tracked::operator==
friend bool operator==(const Tracked &a, const Tracked &b)
Definition: bloaty/third_party/abseil-cpp/absl/container/internal/tracked.h:63
absl::container_internal::Tracked::num_copies_
std::shared_ptr< size_t > num_copies_
Definition: abseil-cpp/absl/container/internal/tracked.h:76
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
absl::container_internal::Tracked::num_moves
size_t num_moves()
Definition: bloaty/third_party/abseil-cpp/absl/container/internal/tracked.h:71
absl::container_internal::Tracked
Definition: abseil-cpp/absl/container/internal/tracked.h:31
T
#define T(upbtypeconst, upbtype, ctype, default_value)
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
absl::container_internal::Tracked::operator!=
friend bool operator!=(const Tracked &a, const Tracked &b)
Definition: bloaty/third_party/abseil-cpp/absl/container/internal/tracked.h:66
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
absl::container_internal::Tracked::val_
T val_
Definition: abseil-cpp/absl/container/internal/tracked.h:74
absl::container_internal::Tracked::num_copies
size_t num_copies()
Definition: bloaty/third_party/abseil-cpp/absl/container/internal/tracked.h:70
b
uint64_t b
Definition: abseil-cpp/absl/container/internal/layout_test.cc:53
absl::container_internal::Tracked::val
const T & val() const
Definition: abseil-cpp/absl/container/internal/tracked.h:61
absl::container_internal::Tracked::operator=
Tracked & operator=(Tracked &&that)
Definition: bloaty/third_party/abseil-cpp/absl/container/internal/tracked.h:54
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
absl::container_internal::Tracked::Tracked
Tracked(const T &val)
Definition: bloaty/third_party/abseil-cpp/absl/container/internal/tracked.h:35
absl::container_internal::Tracked::num_moves_
std::shared_ptr< size_t > num_moves_
Definition: abseil-cpp/absl/container/internal/tracked.h:75
absl::container_internal::Tracked::operator=
Tracked & operator=(const Tracked &that)
Definition: bloaty/third_party/abseil-cpp/absl/container/internal/tracked.h:48
absl::container_internal::Tracked::Tracked
Tracked()
Definition: bloaty/third_party/abseil-cpp/absl/container/internal/tracked.h:33
absl::container_internal::Tracked::Tracked
Tracked(Tracked &&that)
Definition: bloaty/third_party/abseil-cpp/absl/container/internal/tracked.h:42


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:40