ATLAS Offline Software
Loading...
Searching...
No Matches
GlobalSim::Bitset< N, Clamp, Signed > Class Template Reference

Custom Bitset class that can handle clamping of values. More...

#include <BitSpec.h>

Inheritance diagram for GlobalSim::Bitset< N, Clamp, Signed >:
Collaboration diagram for GlobalSim::Bitset< N, Clamp, Signed >:

Public Member Functions

constexpr Bitset (unsigned long long value)
constexpr Bitset (const Bitset &)=default
constexpr Bitset (Bitset &&)=default
constexpr Bitset (const Base &bits)
constexpr Bitset (Base &&bits)
template<std::size_t M>
constexpr Bitset (const std::bitset< M > &other)
template<typename T>
requires std::is_integral_v<T>
constexpr Bitset (T value)

Static Public Attributes

static constexpr auto max
static constexpr auto min

Private Types

using Base = std::bitset<N>

Static Private Member Functions

static constexpr std::uint64_t unsignedMax ()
static constexpr std::int64_t signedMin ()
static constexpr std::int64_t signedMax ()
template<typename T>
static constexpr std::uint64_t convert (T value)

Detailed Description

template<std::size_t N, bool Clamp = false, bool Signed = false>
class GlobalSim::Bitset< N, Clamp, Signed >

Custom Bitset class that can handle clamping of values.

Template Parameters
N
Clamp
Signed

Definition at line 125 of file BitSpec.h.

Member Typedef Documentation

◆ Base

template<std::size_t N, bool Clamp = false, bool Signed = false>
using GlobalSim::Bitset< N, Clamp, Signed >::Base = std::bitset<N>
private

Definition at line 126 of file BitSpec.h.

Constructor & Destructor Documentation

◆ Bitset() [1/7]

template<std::size_t N, bool Clamp = false, bool Signed = false>
GlobalSim::Bitset< N, Clamp, Signed >::Bitset ( unsigned long long value)
inlineconstexpr

Definition at line 176 of file BitSpec.h.

176: Base(convert(value)) {} // Hides the inherited bitset(unsigned long long)
Custom Bitset class that can handle clamping of values.
Definition BitSpec.h:125
std::bitset< N > Base
Definition BitSpec.h:126
static constexpr std::uint64_t convert(T value)
Definition BitSpec.h:144

◆ Bitset() [2/7]

template<std::size_t N, bool Clamp = false, bool Signed = false>
GlobalSim::Bitset< N, Clamp, Signed >::Bitset ( const Bitset< N, Clamp, Signed > & )
constexprdefault

◆ Bitset() [3/7]

template<std::size_t N, bool Clamp = false, bool Signed = false>
GlobalSim::Bitset< N, Clamp, Signed >::Bitset ( Bitset< N, Clamp, Signed > && )
constexprdefault

◆ Bitset() [4/7]

template<std::size_t N, bool Clamp = false, bool Signed = false>
GlobalSim::Bitset< N, Clamp, Signed >::Bitset ( const Base & bits)
inlineconstexpr

Definition at line 183 of file BitSpec.h.

183: Base(bits) {}

◆ Bitset() [5/7]

template<std::size_t N, bool Clamp = false, bool Signed = false>
GlobalSim::Bitset< N, Clamp, Signed >::Bitset ( Base && bits)
inlineconstexpr

Definition at line 184 of file BitSpec.h.

184: Base(std::move(bits)) {}

◆ Bitset() [6/7]

template<std::size_t N, bool Clamp = false, bool Signed = false>
template<std::size_t M>
GlobalSim::Bitset< N, Clamp, Signed >::Bitset ( const std::bitset< M > & other)
inlineconstexpr

Definition at line 188 of file BitSpec.h.

188 {
189 constexpr std::size_t count = (N < M) ? N : M;
190 for (std::size_t i = 0; i < count; ++i) {
191 this->set(i, other[i]);
192 }
193 }

◆ Bitset() [7/7]

template<std::size_t N, bool Clamp = false, bool Signed = false>
template<typename T>
requires std::is_integral_v<T>
GlobalSim::Bitset< N, Clamp, Signed >::Bitset ( T value)
inlineconstexpr

Definition at line 197 of file BitSpec.h.

198 : Base(convert(value)) {}

Member Function Documentation

◆ convert()

template<std::size_t N, bool Clamp = false, bool Signed = false>
template<typename T>
constexpr std::uint64_t GlobalSim::Bitset< N, Clamp, Signed >::convert ( T value)
inlinestaticconstexprprivate

Definition at line 144 of file BitSpec.h.

144 {
145 static_assert(std::is_integral_v<T>);
146
147 if constexpr (!Clamp) {
148 return static_cast<std::uint64_t>(value);
149 } else if constexpr (Signed) {
150 if constexpr (std::is_signed_v<T>) {
151 return std::clamp(static_cast<std::int64_t>(value),signedMin(),signedMax());
152 } else {
153 return std::clamp(static_cast<std::uint64_t>(value),std::uint64_t{0},static_cast<std::uint64_t>(signedMax()));
154 }
155 } else {
156 if constexpr (std::is_signed_v<T>) {
157 if (value < 0)
158 return 0;
159 }
160 return std::clamp(static_cast<std::uint64_t>(value),std::uint64_t{0},unsignedMax());
161 }
162 }
static constexpr std::int64_t signedMin()
Definition BitSpec.h:133
static constexpr std::int64_t signedMax()
Definition BitSpec.h:138
static constexpr std::uint64_t unsignedMax()
Definition BitSpec.h:128

◆ signedMax()

template<std::size_t N, bool Clamp = false, bool Signed = false>
constexpr std::int64_t GlobalSim::Bitset< N, Clamp, Signed >::signedMax ( )
inlinestaticconstexprprivate

Definition at line 138 of file BitSpec.h.

138 {
139 if constexpr (N == 64) return std::numeric_limits<std::int64_t>::max();
140 else return (std::int64_t{1} << (N - 1)) - 1;
141 }

◆ signedMin()

template<std::size_t N, bool Clamp = false, bool Signed = false>
constexpr std::int64_t GlobalSim::Bitset< N, Clamp, Signed >::signedMin ( )
inlinestaticconstexprprivate

Definition at line 133 of file BitSpec.h.

133 {
134 if constexpr (N >= 64) return std::numeric_limits<std::int64_t>::min();
135 else return -(std::int64_t{1} << (N - 1));
136 }

◆ unsignedMax()

template<std::size_t N, bool Clamp = false, bool Signed = false>
constexpr std::uint64_t GlobalSim::Bitset< N, Clamp, Signed >::unsignedMax ( )
inlinestaticconstexprprivate

Definition at line 128 of file BitSpec.h.

128 {
129 if constexpr (N >= 64) return std::numeric_limits<std::uint64_t>::max();
130 else return (std::uint64_t{1} << N) - 1;
131 }

Member Data Documentation

◆ max

template<std::size_t N, bool Clamp = false, bool Signed = false>
auto GlobalSim::Bitset< N, Clamp, Signed >::max
staticconstexpr
Initial value:
= [] {
if constexpr (Signed) return signedMax();
else return unsignedMax();
}()

Definition at line 166 of file BitSpec.h.

166 {
167 if constexpr (Signed) return signedMax();
168 else return unsignedMax();
169 }();

◆ min

template<std::size_t N, bool Clamp = false, bool Signed = false>
auto GlobalSim::Bitset< N, Clamp, Signed >::min
staticconstexpr
Initial value:
= [] {
if constexpr (Signed) return signedMin();
else return std::uint64_t{0};
}()

Definition at line 170 of file BitSpec.h.

170 {
171 if constexpr (Signed) return signedMin();
172 else return std::uint64_t{0};
173 }();

The documentation for this class was generated from the following file: