|
|
|||
File indexing completed on 2026-08-16 09:21:11
0001 // @(#)root/foundation: 0002 // Author: Philippe Canal, April 2026 0003 0004 /************************************************************************* 0005 * Copyright (C) 1995-2026, Rene Brun and Fons Rademakers. * 0006 * All rights reserved. * 0007 * * 0008 * For the licensing terms see $ROOTSYS/LICENSE. * 0009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 0010 *************************************************************************/ 0011 0012 #ifndef ROOT_RAlignmentUtils 0013 #define ROOT_RAlignmentUtils 0014 0015 #include <cassert> 0016 #include <cstddef> 0017 0018 namespace ROOT { 0019 namespace Internal { 0020 0021 /// Return true if \p align is a valid C++ alignment value: strictly positive 0022 /// and a power of two. This is the set of values accepted by 0023 /// `::operator new[](n, std::align_val_t(align))`. 0024 inline constexpr bool IsValidAlignment(std::size_t align) noexcept 0025 { 0026 return align > 0 && (align & (align - 1)) == 0; 0027 } 0028 0029 /// Round \p value up to the next multiple of \p align. 0030 /// \p align must be a power of two (asserted at runtime in debug builds). 0031 template <typename T> 0032 inline constexpr T AlignUp(T value, T align) noexcept 0033 { 0034 assert(IsValidAlignment(static_cast<std::size_t>(align))); // must be a power of two 0035 return (value + align - 1) & ~(align - 1); 0036 } 0037 0038 } // namespace Internal 0039 } // namespace ROOT 0040 0041 #endif // ROOT_RAlignmentUtils
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|