ATLAS Offline Software
Loading...
Searching...
No Matches
ones.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2/*
3 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4*/
11
12
13#ifndef CXXUTILS_ONES_H
14#define CXXUTILS_ONES_H
15
16
17namespace CxxUtils {
18
19
23template <class T>
24inline
25constexpr T ones (unsigned int n)
26{
27 if (n >= sizeof(T) * 8)
28 return ~static_cast<T>(0);
29 // cppcheck-suppress shiftTooManyBits
30 return (static_cast<T>(1) << n) - 1;
31}
32
33
34} // namespace CxxUtils
35
36
37#endif // not CXXUTILS_ONES_H
constexpr T ones(unsigned int n)
Return a bit mask with the lower n bits set.
Definition ones.h:25