FE 0.6.0
A header-only C++ library for writing frontends
Loading...
Searching...
No Matches
enum.h File Reference
#include <compare>
#include <type_traits>
Include dependency graph for enum.h:

Go to the source code of this file.

Classes

struct  fe::is_bit_enum< T >
 

Namespaces

namespace  fe
 

Concepts

concept  fe::BitEnum
 

Functions

Bit operations for enum classs

Provides all kind of bit and comparison operators for an enum class E.

Note that the bit operators return E's underlying type and not the original enum E. This is because the result may not be a valid enum value. For the same reason, it doesn't make sense to declare operators such as &=. Use like this:

using fe::operator&;
using fe::operator|;
using fe::operator^;
using fe::operator<=>;
using fe::operator==;
using fe::operator!=;
enum class MyEnum : unsigned {
A = 1 << 0,
B = 1 << 1,
C = 1 << 2,
};
template<> struct fe::is_bit_enum<MyEnum> : std::true_type { };
template<BitEnum E>
constexpr auto fe::operator& (E x, E y)
 
template<BitEnum E>
constexpr auto fe::operator& (std::underlying_type_t< E > x, E y)
 
template<BitEnum E>
constexpr auto fe::operator& (E x, std::underlying_type_t< E > y)
 
template<BitEnum E>
constexpr auto fe::operator| (E x, E y)
 
template<BitEnum E>
constexpr auto fe::operator| (std::underlying_type_t< E > x, E y)
 
template<BitEnum E>
constexpr auto fe::operator| (E x, std::underlying_type_t< E > y)
 
template<BitEnum E>
constexpr auto fe::operator^ (E x, E y)
 
template<BitEnum E>
constexpr auto fe::operator^ (std::underlying_type_t< E > x, E y)
 
template<BitEnum E>
constexpr auto fe::operator^ (E x, std::underlying_type_t< E > y)
 
template<BitEnum E>
constexpr std::strong_ordering fe::operator<=> (std::underlying_type_t< E > x, E y)
 
template<BitEnum E>
constexpr std::strong_ordering fe::operator<=> (E x, std::underlying_type_t< E > y)
 
template<BitEnum E>
constexpr bool fe::operator== (std::underlying_type_t< E > x, E y)
 
template<BitEnum E>
constexpr bool fe::operator!= (std::underlying_type_t< E > x, E y)
 
template<BitEnum E>
constexpr bool fe::operator== (E x, std::underlying_type_t< E > y)
 
template<BitEnum E>
constexpr bool fe::operator!= (E x, std::underlying_type_t< E > y)
 

Variables

is_enum
template<class T >
constexpr bool fe::is_bit_enum_v = is_bit_enum<T>::value