Capacity.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- Capacity.h - Generic computation of ADT memory use -----*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines the capacity function that computes the amount of
  15. // memory used by an ADT.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_SUPPORT_CAPACITY_H
  19. #define LLVM_SUPPORT_CAPACITY_H
  20. #include <cstddef>
  21. namespace llvm {
  22. template <typename T>
  23. static inline size_t capacity_in_bytes(const T &x) {
  24. // This default definition of capacity should work for things like std::vector
  25. // and friends. More specialized versions will work for others.
  26. return x.capacity() * sizeof(typename T::value_type);
  27. }
  28. } // end namespace llvm
  29. #endif
  30. #ifdef __GNUC__
  31. #pragma GCC diagnostic pop
  32. #endif