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