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
variant.h
Go to the documentation of this file.
#pragma once
#include <
concepts
>
#include <
sstream
>
#include <
string
>
#include <
type_traits
>
#include <
variant
>
#include <
librepr/name/type.h
>
#include <
librepr/util/collections/list.h
>
#include <
librepr/util/overload.h
>
#include "
category.h
"
namespace
librepr
{
template
<
typename
T>
struct
Reflect
;
namespace
detail {
template
<
typename
T>
struct
VariantDetector
{
static
constexpr
bool
value
=
false
;
};
struct
VariantDetector
{
…
};
template
<
template
<
typename
...>
class
Variant
,
typename
...
Ts
>
requires
std::derived_from<
Variant
<
Ts
...>,
std::variant
<
Ts
...>>
struct
VariantDetector
<
Variant
<
Ts
...>
const
> {
static
constexpr
bool
value
=
true
;
using
alternatives
=
typename
TypeList
<
Ts
...>
::template
map<std::add_const_t>
;
};
struct
VariantDetector
<
Variant
<
Ts
...>
const
> {
…
};
template
<
template
<
typename
...>
class
Variant
,
typename
...
Ts
>
requires
std::derived_from<
Variant
<
Ts
...>,
std::variant
<
Ts
...>>
struct
VariantDetector
<
Variant
<
Ts
...>> {
static
constexpr
bool
value
=
true
;
using
alternatives
=
TypeList
<
Ts
...>;
};
struct
VariantDetector
<
Variant
<
Ts
...>> {
…
};
}
// namespace detail
template
<
typename
T>
concept
is_variant
=
detail::VariantDetector<T>::value
;
template
<is_variant T>
struct
Reflect
<T> : category::Type<T> {
using
type
= T;
using
alternatives
=
typename
detail::VariantDetector<T>::alternatives
;
constexpr
static
bool
can_descend =
true
;
template
<
typename
V>
static
void
visit
(V&&
visitor
,
type
&
obj
) {
std::visit
(
[&
visitor
]<
typename
U
>(
U
&&
alternative
) {
using
alt_type
=
std::remove_reference_t<U>
;
visitor
(
category::Value
<
Reflect<alt_type>
>{std::forward<U>(
alternative
)});
},
obj
);
}
static
void
visit
(V&&
visitor
,
type
&
obj
) {
…
}
template
<
typename
V>
static
void
visit
(V&&
visitor
) {
alternatives::for_each([&
visitor
]<
typename
U
>() {
visitor
(
Reflect<U>
{}); });
}
static
void
visit
(V&&
visitor
) {
…
}
};
}
// namespace librepr
include
librepr
reflection
variant.h
Generated by
1.9.8, using the excellent
Doxygen Awesome
Theme