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
};
47
48
namespace
detail {
49
52
struct
container_spec
{
53
std::meta::info
tmpl
;
54
container_kind
kind
;
55
};
56
62
consteval
std::array<container_spec, 3>
reference_containers
() {
63
return
{{
64
{^^std::vector,
container_kind::sequence
},
65
{^^std::map,
container_kind::map
},
66
{^^std::unordered_map,
container_kind::map
},
67
}};
68
}
69
70
}
// namespace detail
71
76
consteval
bool
is_reference_container
(std::meta::info type) {
77
if
(!std::meta::has_template_arguments(type))
78
return
false
;
79
const
std::meta::info tmpl{std::meta::template_of(type)};
80
for
(
const
detail::container_spec
& c :
detail::reference_containers
())
81
if
(c.tmpl == tmpl)
82
return
true
;
83
return
false
;
84
}
85
91
consteval
container_kind
container_kind_of
(std::meta::info type) {
92
const
std::meta::info tmpl{std::meta::template_of(type)};
93
for
(
const
detail::container_spec
& c :
detail::reference_containers
())
94
if
(c.tmpl == tmpl)
95
return
c.kind;
96
return
container_kind::sequence
;
// unreachable given the precondition
97
}
98
109
consteval
bool
container_is_contiguous
(std::meta::info type) {
110
return
std::meta::has_template_arguments(type) &&
111
std::meta::template_of(type) == ^^std::vector;
112
}
113
120
template
<
class
B>
121
concept
rod_binds_containers
=
122
requires
(
typename
B::module_type& m,
const
char
* s) {
123
B::template bind_container<std::vector<int>>(m, s);
124
};
125
126
}
// namespace welder
welder::rod_binds_containers
Does rod B implement the optional bind_container hook (i.e.
Definition
containers.hpp:121
welder::detail::reference_containers
consteval std::array< container_spec, 3 > reference_containers()
The containers welder binds opaquely — exactly those the frameworks' bind_vector / bind_map support.
Definition
containers.hpp:62
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:109
welder::container_kind_of
consteval container_kind container_kind_of(std::meta::info type)
The opaque-binder kind of type.
Definition
containers.hpp:91
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::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:76
welder::detail::container_spec
One row of the reference-container table: a container template paired with the opaque binder kind it ...
Definition
containers.hpp:52
welder::detail::container_spec::tmpl
std::meta::info tmpl
The class template, e.g.
Definition
containers.hpp:53
welder::detail::container_spec::kind
container_kind kind
Which opaque binder registers it.
Definition
containers.hpp:54
src
welder
containers.hpp
Generated by
1.17.0