15[[nodiscard]]
inline size_t heapBytes(
const std::vector<T> & vec )
17 constexpr bool hasHeapBytes =
requires(
const T& t ) { t.heapBytes(); };
18 if constexpr ( hasHeapBytes )
20 size_t res = vec.capacity() *
sizeof( T );
21 for (
const T & t : vec )
27 return vec.capacity() *
sizeof( T );
31template<
typename T,
typename U>
34 constexpr bool hasHeapBytes =
requires(
const T & t ) { t.heapBytes(); };
35 if constexpr ( hasHeapBytes )
37 size_t res = vec.
size() *
sizeof( T );
38 for (
const T & t : vec )
44 return vec.
size() *
sizeof( T );
50[[nodiscard]]
inline size_t heapBytes(
const std::unique_ptr<T> & ptr )
54 return sizeof( T ) + ptr->heapBytes();
59[[nodiscard]]
inline size_t heapBytes(
const std::shared_ptr<T> & ptr )
63 return sizeof( T ) + ptr->heapBytes();
68[[nodiscard]]
inline size_t heapBytes(
const std::function<T> & )
74template<
typename ...Ts>
75[[nodiscard]]
inline size_t heapBytes(
const phmap::flat_hash_map<Ts...>& hashMap )
82 const auto cap = hashMap.capacity();
83 constexpr size_t kWidth = 16;
84 return cap + kWidth + cap *
sizeof(
typename phmap::flat_hash_map<Ts...>::slot_type );
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:20
std::size_t size() const
Definition MRMesh/MRVector.h:42
size_t heapBytes(const std::vector< T > &vec)
returns the amount of memory given vector occupies on heap
Definition MRHeapBytes.h:15