SlHelpers
Toggle main menu visibility
Loading...
Searching...
No Matches
Enum.h
1
// SPDX-License-Identifier: GPL-2.0-only
2
3
#pragma once
4
5
#include <type_traits>
6
7
namespace
SlHelpers {
8
10
template
<
typename
Enum>
11
class
EnumRange
{
12
public
:
14
using
Underlying
= std::underlying_type_t<Enum>;
15
17
struct
iterator
{
19
Underlying
v
;
20
22
Enum
operator*
()
const
{
return
static_cast<
Enum
>
(
v
); }
23
25
iterator
&
operator++
() {
26
++
v
;
27
return
*
this
;
28
}
29
31
bool
operator==
(
const
iterator
&other)
const
{
return
v
== other.
v
; }
33
bool
operator!=
(
const
iterator
&other)
const
{
return
v
!= other.
v
; }
34
};
35
37
iterator
begin
()
const
{
return
{
static_cast<
Underlying
>
(Enum::First) }; }
39
iterator
end
()
const
{
return
{
static_cast<
Underlying
>
(Enum::Last) + 1 }; }
40
};
41
42
}
SlHelpers::EnumRange
Helper class to iterate over enum values from Enum::First to Enum::Last.
Definition
Enum.h:11
SlHelpers::EnumRange::end
iterator end() const
Returns an iterator to the end of the enum range.
Definition
Enum.h:39
SlHelpers::EnumRange::begin
iterator begin() const
Returns an iterator to the beginning of the enum range.
Definition
Enum.h:37
SlHelpers::EnumRange::Underlying
std::underlying_type_t< Enum > Underlying
Type of the underlying enum values.
Definition
Enum.h:14
SlHelpers::EnumRange::iterator
Iterator class to iterate over enum values.
Definition
Enum.h:17
SlHelpers::EnumRange::iterator::operator*
Enum operator*() const
Dereference operator to get the current enum value.
Definition
Enum.h:22
SlHelpers::EnumRange::iterator::operator!=
bool operator!=(const iterator &other) const
Inequality operator to compare two iterators.
Definition
Enum.h:33
SlHelpers::EnumRange::iterator::v
Underlying v
Current value of the iterator.
Definition
Enum.h:19
SlHelpers::EnumRange::iterator::operator++
iterator & operator++()
Pre-increment operator to move to the next enum value.
Definition
Enum.h:25
SlHelpers::EnumRange::iterator::operator==
bool operator==(const iterator &other) const
Equality operator to compare two iterators.
Definition
Enum.h:31
include
helpers
Enum.h
Generated by
1.17.0