Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef ABSL_CONTAINER_INTERNAL_NODE_HASH_POLICY_H_
00034 #define ABSL_CONTAINER_INTERNAL_NODE_HASH_POLICY_H_
00035
00036 #include <cassert>
00037 #include <cstddef>
00038 #include <memory>
00039 #include <type_traits>
00040 #include <utility>
00041
00042 namespace absl {
00043 namespace container_internal {
00044
00045 template <class Reference, class Policy>
00046 struct node_hash_policy {
00047 static_assert(std::is_lvalue_reference<Reference>::value, "");
00048
00049 using slot_type = typename std::remove_cv<
00050 typename std::remove_reference<Reference>::type>::type*;
00051
00052 template <class Alloc, class... Args>
00053 static void construct(Alloc* alloc, slot_type* slot, Args&&... args) {
00054 *slot = Policy::new_element(alloc, std::forward<Args>(args)...);
00055 }
00056
00057 template <class Alloc>
00058 static void destroy(Alloc* alloc, slot_type* slot) {
00059 Policy::delete_element(alloc, *slot);
00060 }
00061
00062 template <class Alloc>
00063 static void transfer(Alloc*, slot_type* new_slot, slot_type* old_slot) {
00064 *new_slot = *old_slot;
00065 }
00066
00067 static size_t space_used(const slot_type* slot) {
00068 if (slot == nullptr) return Policy::element_space_used(nullptr);
00069 return Policy::element_space_used(*slot);
00070 }
00071
00072 static Reference element(slot_type* slot) { return **slot; }
00073
00074 template <class T, class P = Policy>
00075 static auto value(T* elem) -> decltype(P::value(elem)) {
00076 return P::value(elem);
00077 }
00078
00079 template <class... Ts, class P = Policy>
00080 static auto apply(Ts&&... ts) -> decltype(P::apply(std::forward<Ts>(ts)...)) {
00081 return P::apply(std::forward<Ts>(ts)...);
00082 }
00083 };
00084
00085 }
00086 }
00087
00088 #endif // ABSL_CONTAINER_INTERNAL_NODE_HASH_POLICY_H_