diff options
Diffstat (limited to 'support/ToolchainSupport.h')
-rw-r--r-- | support/ToolchainSupport.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/support/ToolchainSupport.h b/support/ToolchainSupport.h index 87e9bd2bc8..b9d9103652 100644 --- a/support/ToolchainSupport.h +++ b/support/ToolchainSupport.h @@ -268,6 +268,23 @@ inline std::string to_string(bool value) str << std::boolalpha << value; return str.str(); } + +// std::align is missing in GCC 4.9 +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57350 +inline void *align(std::size_t alignment, std::size_t size, void *&ptr, std::size_t &space) +{ + std::uintptr_t pn = reinterpret_cast<std::uintptr_t>(ptr); + std::uintptr_t aligned = (pn + alignment - 1) & -alignment; + std::size_t padding = aligned - pn; + if(space < size + padding) + { + return nullptr; + } + + space -= padding; + + return ptr = reinterpret_cast<void *>(aligned); +} } // namespace cpp11 namespace cpp14 |