Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RAlignmentUtils.hxx
Go to the documentation of this file.
1// @(#)root/foundation:
2// Author: Philippe Canal, April 2026
3
4/*************************************************************************
5 * Copyright (C) 1995-2026, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_RAlignmentUtils
13#define ROOT_RAlignmentUtils
14
15#include <cassert>
16#include <cstddef>
17
18namespace ROOT {
19namespace Internal {
20
21/// Return true if \p align is a valid C++ alignment value: strictly positive
22/// and a power of two. This is the set of values accepted by
23/// `::operator new[](n, std::align_val_t(align))`.
24inline constexpr bool IsValidAlignment(std::size_t align) noexcept
25{
26 return align > 0 && (align & (align - 1)) == 0;
27}
28
29/// Round \p value up to the next multiple of \p align.
30/// \p align must be a power of two (asserted at runtime in debug builds).
31template <typename T>
32inline constexpr T AlignUp(T value, T align) noexcept
33{
34 assert(IsValidAlignment(static_cast<std::size_t>(align))); // must be a power of two
35 return (value + align - 1) & ~(align - 1);
36}
37
38} // namespace Internal
39} // namespace ROOT
40
41#endif // ROOT_RAlignmentUtils
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
constexpr T AlignUp(T value, T align) noexcept
Round value up to the next multiple of align.
constexpr bool IsValidAlignment(std::size_t align) noexcept
Return true if align is a valid C++ alignment value: strictly positive and a power of two.