File indexing completed on 2025-01-18 09:27:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #ifndef ABSL_CONTAINER_INTERNAL_NODE_SLOT_POLICY_H_
0034 #define ABSL_CONTAINER_INTERNAL_NODE_SLOT_POLICY_H_
0035
0036 #include <cassert>
0037 #include <cstddef>
0038 #include <memory>
0039 #include <type_traits>
0040 #include <utility>
0041
0042 #include "absl/base/config.h"
0043
0044 namespace absl {
0045 ABSL_NAMESPACE_BEGIN
0046 namespace container_internal {
0047
0048 template <class Reference, class Policy>
0049 struct node_slot_policy {
0050 static_assert(std::is_lvalue_reference<Reference>::value, "");
0051
0052 using slot_type = typename std::remove_cv<
0053 typename std::remove_reference<Reference>::type>::type*;
0054
0055 template <class Alloc, class... Args>
0056 static void construct(Alloc* alloc, slot_type* slot, Args&&... args) {
0057 *slot = Policy::new_element(alloc, std::forward<Args>(args)...);
0058 }
0059
0060 template <class Alloc>
0061 static void destroy(Alloc* alloc, slot_type* slot) {
0062 Policy::delete_element(alloc, *slot);
0063 }
0064
0065
0066 template <class Alloc>
0067 static std::true_type transfer(Alloc*, slot_type* new_slot,
0068 slot_type* old_slot) {
0069 *new_slot = *old_slot;
0070 return {};
0071 }
0072
0073 static size_t space_used(const slot_type* slot) {
0074 if (slot == nullptr) return Policy::element_space_used(nullptr);
0075 return Policy::element_space_used(*slot);
0076 }
0077
0078 static Reference element(slot_type* slot) { return **slot; }
0079
0080 template <class T, class P = Policy>
0081 static auto value(T* elem) -> decltype(P::value(elem)) {
0082 return P::value(elem);
0083 }
0084
0085 template <class... Ts, class P = Policy>
0086 static auto apply(Ts&&... ts) -> decltype(P::apply(std::forward<Ts>(ts)...)) {
0087 return P::apply(std::forward<Ts>(ts)...);
0088 }
0089 };
0090
0091 }
0092 ABSL_NAMESPACE_END
0093 }
0094
0095 #endif