welder
0.1.0
Bindings for annotated C++ types, from C++26 reflection
Toggle main menu visibility
Loading...
Searching...
No Matches
containers.hpp
Go to the documentation of this file.
1
#pragma once
2
#include <array>
3
#include <map>
4
#include <meta>
5
#include <unordered_map>
6
#include <vector>
7
39
40
namespace
welder::inline v0 {
41
43
enum class
container_kind
:
unsigned
char
{
44
sequence
,
45
map
,
46
fixed_sequence
,
50
};
51
52
namespace
detail {
53
56
struct
container_spec
{
57
std::meta::info
tmpl
;
58
container_kind
kind
;
59
};
60
73
consteval
std::array<container_spec, 4>
reference_containers
() {
74
return
{{
75
{^^std::vector,
container_kind::sequence
},
76
{^^std::array,
container_kind::fixed_sequence
},
77
{^^std::map,
container_kind::map
},
78
{^^std::unordered_map,
container_kind::map
},
79
}};
80
}
81
82
}
// namespace detail
83
88
consteval
bool
is_reference_container
(std::meta::info type) {
89
if
(!std::meta::has_template_arguments(type))
90
return
false
;
91
const
std::meta::info tmpl{std::meta::template_of(type)};
92
for
(
const
detail::container_spec
& c :
detail::reference_containers
())
93
if
(c.tmpl == tmpl)
94
return
true
;
95
return
false
;
96
}
97
103
consteval
container_kind
container_kind_of
(std::meta::info type) {
104
const
std::meta::info tmpl{std::meta::template_of(type)};
105
for
(
const
detail::container_spec
& c :
detail::reference_containers
())
106
if
(c.tmpl == tmpl)
107
return
c.kind;
108
return
container_kind::sequence
;
// unreachable given the precondition
109
}
110
122
consteval
bool
container_is_contiguous
(std::meta::info type) {
123
if
(!std::meta::has_template_arguments(type))
124
return
false
;
125
const
std::meta::info tmpl{std::meta::template_of(type)};
126
return
tmpl == ^^std::vector || tmpl == ^^std::array;
127
}
128
135
template
<
class
B>
136
concept
rod_binds_containers
=
137
requires
(
typename
B::module_type& m,
const
char
* s) {
138
B::template bind_container<std::vector<int>>(m, s);
139
};
140
141
}
// namespace welder
welder::rod_binds_containers
Does rod B implement the optional bind_container hook (i.e.
Definition
containers.hpp:136
welder::detail::reference_containers
consteval std::array< container_spec, 4 > reference_containers()
The containers welder binds opaquely — exactly those the frameworks' bind_vector / bind_map support.
Definition
containers.hpp:73
welder
Definition
annotations.hpp:18
welder::container_is_contiguous
consteval bool container_is_contiguous(std::meta::info type)
Is type a contiguous sequence — one whose elements live in a single block reachable via ....
Definition
containers.hpp:122
welder::container_kind_of
consteval container_kind container_kind_of(std::meta::info type)
The opaque-binder kind of type.
Definition
containers.hpp:103
welder::container_kind
container_kind
Which opaque binder a reference-bound container uses.
Definition
containers.hpp:43
welder::container_kind::map
@ map
A bind_map container: std::map, std::unordered_map.
Definition
containers.hpp:45
welder::container_kind::fixed_sequence
@ fixed_sequence
A fixed-size sequence: std::array<T, N>.
Definition
containers.hpp:46
welder::container_kind::sequence
@ sequence
A bind_vector container: std::vector.
Definition
containers.hpp:44
welder::is_reference_container
consteval bool is_reference_container(std::meta::info type)
Is type one of the containers welder can bind by reference (opaquely)?
Definition
containers.hpp:88
welder::detail::container_spec
One row of the reference-container table: a container template paired with the opaque binder kind it ...
Definition
containers.hpp:56
welder::detail::container_spec::tmpl
std::meta::info tmpl
The class template, e.g.
Definition
containers.hpp:57
welder::detail::container_spec::kind
container_kind kind
Which opaque binder registers it.
Definition
containers.hpp:58
src
welder
containers.hpp
Generated by
1.17.0