codex
Loading...
Searching...
No Matches
fields.hpp
Go to the documentation of this file.
1#ifndef CODEX_REFLECTION_FIELDS_DETAIL_HPP
2#define CODEX_REFLECTION_FIELDS_DETAIL_HPP
3
4#include <cstdio>
5#include <tuple>
6#include <utility>
7
8namespace codex::refl::detail {
9
17template<auto>
18struct to_any {
19 template<typename T> constexpr operator T(void);
20};
21
27template<std::size_t N> struct field_tuple_impl;
28
29// Could potentially be implemented in a more concise manner with auxiliary
30// infrastructure such as Boost.Preprocessor.
31#define X(n, ...) \
32 template<> \
33 struct field_tuple_impl<n> { \
34 decltype(auto) operator()(auto &&x) { \
35 auto &&[__VA_ARGS__] = std::forward<decltype(x)>(x); \
36 return std::tie(__VA_ARGS__); \
37 } \
38 };
39X(1, _0)
40X(2, _0, _1)
41X(3, _0, _1, _2)
42X(4, _0, _1, _2, _3)
43#undef X
44
45}
46
47#endif
#define T(f, T, C)
Definition bench.cpp:136
Definition fields.hpp:8
_1 _2
Definition fields.hpp:42
_0
Definition fields.hpp:40
_1 _1
Definition fields.hpp:42
#define X(n,...)
Definition fields.hpp:31
Implementation of creating a std::tuple from the fields of a struct.
Definition fields.hpp:27
Structure which can be ostensibly converted to any other.
Definition fields.hpp:18