Skip to content

Commit

Permalink
flags: Allow a bitFlags_t to be stored by an atomic underlying type
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmux committed May 21, 2024
1 parent 36999ae commit 86ba954
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion substrate/flags
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
#ifndef SUBSTRATE_FLAGS
#define SUBSTRATE_FLAGS

#include <atomic>
#include <type_traits>

namespace substrate
{
template<typename T> struct isAtomicIntegral : std::is_integral<T> { };
template<typename T> struct isAtomicIntegral<std::atomic<T>> : std::is_integral<T> { };

template<typename T> constexpr inline bool isAtomicIntegral_v = isAtomicIntegral<T>::value;

template<typename storage_t, typename enum_t> struct bitFlags_t
{
private:
static_assert(std::is_integral_v<storage_t>, "bitFlags_t must be backed by an integral type");
static_assert(isAtomicIntegral_v<storage_t>, "bitFlags_t must be backed by an integral type");
static_assert(std::is_enum_v<enum_t>, "bitFlags_t must be enumerated by an enum");
storage_t value{};

Expand Down

0 comments on commit 86ba954

Please sign in to comment.