jaulib v1.3.6
Jau Support Library (C++, Java, ..)
Loading...
Searching...
No Matches
jau::enums Namespace Reference

Author: Sven Gothel sgoth.nosp@m.el@j.nosp@m.ausof.nosp@m.t.co.nosp@m.m Copyright Gothel Software e.K. More...

Classes

class  enum_info
 Enumeration info template class including iterator (enum_iterator) More...
 
class  enum_iterator
 Enumeration iterator, see enum_info. More...
 
struct  is_enum_info
 template< class T > is_enum_info<T>::value compile-time Type Trait, determining whether the given template class is a enum_info type. More...
 
struct  is_enum_info< T, std::void_t< typename T::enum_info_tag > >
 template< class T > is_enum_info<T>::value compile-time Type Trait, determining whether the given template class is a enum_info type. More...
 
struct  NameTable
 
struct  ValueTable
 

Functions

template<typename E, std::enable_if_t< std::is_enum_v< E > > * = nullptr>
constexpr void append_bitstr (std::string &out, E mask, E bit, const std::string &bitstr, bool &comma)
 
template<typename E, E V>
consteval_cxx20 const char * enum_funcname () noexcept
 clang + gcc
 
template<auto... Vargs>
consteval_cxx20 NameTable< Vargs... > get_names () noexcept
 
template<typename... Args>
constexpr ValueTable< std::common_type_t< Args... >, sizeof...(Args)> get_values (Args... args) noexcept
 
template<typename E, std::enable_if_t< std::is_enum_v< E > > * = nullptr>
constexpr bool has_any (const E mask, const E bits) noexcept
 
template<auto V, std::enable_if_t< std::is_enum_v< decltype(V)> > * = nullptr>
consteval_cxx20 bool is_enum () noexcept
 
template<typename E, std::enable_if_t< std::is_enum_v< E > > * = nullptr>
constexpr bool is_set (const E mask, const E bits) noexcept
 
template<auto V, std::enable_if_t< std::is_enum_v< decltype(V)> > * = nullptr>
consteval_cxx20 std::string_view long_name () noexcept
 
template<auto V, std::enable_if_t< std::is_enum_v< decltype(V)> > * = nullptr>
consteval_cxx20 std::string_view name () noexcept
 
template<typename E, std::enable_if_t< std::is_enum_v< E > > * = nullptr>
constexpr std::underlying_type_t< E > number (const E v) noexcept
 
template<typename E, std::enable_if_t< std::is_enum_v< E > > * = nullptr>
constexpr bool operator!= (const E lhs, const E rhs) noexcept
 
template<typename E, std::enable_if_t< std::is_enum_v< E > > * = nullptr>
constexpr E operator& (const E lhs, const E rhs) noexcept
 
template<typename E, std::enable_if_t< std::is_enum_v< E > > * = nullptr>
constexpr E & operator&= (E &lhs, const E rhs) noexcept
 
template<typename E, std::enable_if_t< std::is_enum_v< E > > * = nullptr>
constexpr std::underlying_type_t< E > operator* (const E v) noexcept
 
template<typename enum_info_t, std::enable_if_t< is_enum_info< enum_info_t >::value > * = nullptr>
std::ostream & operator<< (std::ostream &os, const enum_info_t &v)
 
template<typename T, std::enable_if_t< std::is_enum_v< T > > * = nullptr>
std::ostream & operator<< (std::ostream &os, const T v)
 
template<typename E, std::enable_if_t< std::is_enum_v< E > > * = nullptr>
constexpr bool operator== (const E lhs, const E rhs) noexcept
 
template<typename E, std::enable_if_t< std::is_enum_v< E > > * = nullptr>
constexpr E operator^ (const E lhs, const E rhs) noexcept
 
template<typename E, std::enable_if_t< std::is_enum_v< E > > * = nullptr>
constexpr E & operator^= (E &lhs, const E rhs) noexcept
 
template<typename E, std::enable_if_t< std::is_enum_v< E > > * = nullptr>
constexpr E operator| (const E lhs, const E rhs) noexcept
 
template<typename E, std::enable_if_t< std::is_enum_v< E > > * = nullptr>
constexpr E & operator|= (E &lhs, const E rhs) noexcept
 
template<typename E, std::enable_if_t< std::is_enum_v< E > > * = nullptr>
constexpr E operator~ (const E rhs) noexcept
 
template<typename E, std::enable_if_t< std::is_enum_v< E > > * = nullptr>
constexpr E & write (E &store, const E bits, bool set) noexcept
 If set==true, sets the bits in store, i.e.
 

Detailed Description

Author: Sven Gothel sgoth.nosp@m.el@j.nosp@m.ausof.nosp@m.t.co.nosp@m.m Copyright Gothel Software e.K.

SPDX-License-Identifier: MIT

This Source Code Form is subject to the terms of the MIT License If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/license/mit/. Provides scoped enum type support functionality, including to_string, enum bitfield operations, etc.

Due to lack of C++26 reflection, basic enum function definition is performed via macros to access value names outside constexpr templates.

Overview

  • Define your enum class manually
  • Use one of the following enum class helper function generator
    • JAU_MAKE_ENUM_STRING for non-bitfield enum values
    • JAU_MAKE_BITFIELD_ENUM_STRING for bitfield enum values
    • JAU_MAKE_ENUM_INFO for typedef E_info_t with E enum class type using enum_info<E, ...>
      • enum_info<E, ...> provides iterator and further basic information for E
  • Following methods are made available via the generator JAU_MAKE_ENUM_STRING, assuming E is the enum class type
    • constexpr std::string_view long_name(const E v) noexcept
      • returns a long string, e.g. E::value
    • constexpr std::string_view name(const E v) noexcept
      • returns a short string, e.g. value
    • constexpr std::string to_string(const E v)
      • returns a short string, e.g. value.
  • Following methods are made available via the generator JAU_MAKE_BITFIELD_ENUM_STRING
    • all methods from JAU_MAKE_ENUM_STRING, while to_string(const E v) returns the set bit values, e.g. [cat, mouse]
  • General support constexpr template functions are available in the jau::enums namespace, assuming E is the enum class type, v an enum value and U the underlying type
    • constexpr U number(const E v) noexcept
      • returns the integral underlying value
    • constexpr U operator*(const E v) noexcept
      • this dereferencing overload operator also returns the integral underlying value like number
    • constexpr bool is_set(const E mask, const E bits) noexcept
      • returns true if mask contains given bits, otherwise false
    • constexpr void append_bitstr(std::string& out, E mask, E bit, const std::string& bitstr, bool& comma)
      • appends bitstr to out if mask contains bit, prepends a comma if comma and sets comma to true.
    • Equality- and bit-operations, e.g.
    • constexpr std::string_view long_name<auto v>() noexcept
      • returns a long string, e.g. E::value
    • constexpr std::string_view name<auto v>() noexcept
      • returns a short string, e.g. value
    • get_names, get_values