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 {
46};
47
48namespace detail {
49
53 std::meta::info tmpl;
55};
56
62consteval 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
76consteval 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)};
81 if (c.tmpl == tmpl)
82 return true;
83 return false;
84}
85
91consteval container_kind container_kind_of(std::meta::info type) {
92 const std::meta::info tmpl{std::meta::template_of(type)};
94 if (c.tmpl == tmpl)
95 return c.kind;
96 return container_kind::sequence; // unreachable given the precondition
97}
98
109consteval 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
120template <class B>
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
Does rod B implement the optional bind_container hook (i.e.
consteval std::array< container_spec, 3 > 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.
@ 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.