welder 0.1.0
Bindings for annotated C++ types, from C++26 reflection
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
40namespace welder::inline v0 {
41
43enum class container_kind : unsigned char {
50};
51
52namespace detail {
53
57 std::meta::info tmpl;
59};
60
73consteval 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
88consteval 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)};
93 if (c.tmpl == tmpl)
94 return true;
95 return false;
96}
97
103consteval container_kind container_kind_of(std::meta::info type) {
104 const std::meta::info tmpl{std::meta::template_of(type)};
106 if (c.tmpl == tmpl)
107 return c.kind;
108 return container_kind::sequence; // unreachable given the precondition
109}
110
122consteval 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
135template <class B>
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
Does rod B implement the optional bind_container hook (i.e.
consteval std::array< container_spec, 4 > reference_containers()
The containers welder binds opaquely — exactly those the frameworks' bind_vector / bind_map support.
consteval bool container_is_contiguous(std::meta::info type)
Is type a contiguous sequence — one whose elements live in a single block reachable via ....
consteval container_kind container_kind_of(std::meta::info type)
The opaque-binder kind of type.
container_kind
Which opaque binder a reference-bound container uses.
@ map
A bind_map container: std::map, std::unordered_map.
@ fixed_sequence
A fixed-size sequence: std::array<T, N>.
@ sequence
A bind_vector container: std::vector.
consteval bool is_reference_container(std::meta::info type)
Is type one of the containers welder can bind by reference (opaquely)?
One row of the reference-container table: a container template paired with the opaque binder kind it ...
std::meta::info tmpl
The class template, e.g.
container_kind kind
Which opaque binder registers it.