repr
0.1
Reconstructable string representations and more
Toggle main menu visibility
Main Page
Installation
Usage
Customization
Extending
FAQ
CI Results
Test
Benchmark
API Documentation
Namespace List
Namespace List
Namespace Members
All
_
a
c
d
e
f
g
i
l
m
n
o
p
r
s
t
u
v
w
Functions
_
a
c
d
e
f
g
i
l
m
n
o
r
s
t
u
v
w
Variables
Typedefs
Enumerations
Concept List
Class List
Class List
Class Index
Class Hierarchy
Class Members
All
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
~
Functions
_
a
c
e
f
g
i
l
m
n
o
p
r
s
t
v
w
~
Variables
a
b
c
d
e
f
g
i
k
l
m
n
o
p
q
r
s
t
u
v
Typedefs
a
c
d
e
f
g
h
l
m
p
r
s
t
u
v
w
Enumerations
Enumerator
Related Symbols
File List
File List
File Members
All
_
l
n
o
r
u
Variables
Macros
_
l
o
r
u
Examples
Source Code
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Concepts
Loading...
Searching...
No Matches
range.h
Go to the documentation of this file.
#pragma once
#include <
array
>
#include <
cstddef
>
#include <
utility
>
#include <
string_view
>
#include <
bit
>
#include "
util.h
"
namespace
librepr::ctei
{
template
<auto First, auto Last = First>
struct
Range
{
static_assert
(
Last
>=
First
);
constexpr
static
auto
size
=
Last
-
First
+ 1;
constexpr
static
auto
min
=
First
;
constexpr
static
auto
max
=
Last
;
template
<auto Idx>
requires
(
Idx
<=
size
)
constexpr
static
auto
get
=
Idx
+
First
;
template
<std::
size_t
amount = 1>
using
expand
=
Range<First, max + static_cast<decltype(max)>
(
amount
)>;
private
:
template
<
typename
T,
EnumKind
Kind
,
std::size_t
...
Idx
>
static
consteval
auto
get_enum_names(
std::index_sequence<Idx...>
){
return
std::array
{
std::string_view
{
enum_name<T, to_underlying<T, Kind>
(Range::template
get<Idx>
)>}...};
}
public
:
template
<
typename
T, EnumKind Kind>
constexpr
static
auto
enum_names
=
get_enum_names<T, Kind>
(
std::make_index_sequence<size>
{});
[[
nodiscard
]]
constexpr
static
bool
is_binary_powers
()
noexcept
{
if
constexpr
(
min
>= 0 &&
max
<= 2) {
// special case ranges containing only 0-2
return
true
;
}
else
if
constexpr
(
std::has_single_bit
(
static_cast<
std::size_t
>
(
min
))) {
// offset is power of 2 - range must contain element at (offset + 0)
return
size
== 1;
}
return
false
;
}
[[
nodiscard
]]
constexpr
static
bool
is_binary_powers
()
noexcept
{
…
}
[[
nodiscard
]]
constexpr
static
bool
contains
(
auto
value)
noexcept
{
return
value >=
min
&& value <=
max
;
}
[[
nodiscard
]]
constexpr
static
bool
contains
(
auto
value)
noexcept
{
…
}
};
struct
Range
{
…
};
}
// namespace librepr::ctei
include
librepr
enum
range.h
Generated by
1.9.8, using the excellent
Doxygen Awesome
Theme