parcel 0.2.2
Wrappable, wire-transferable C++23 value system with JSON serialization
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1#pragma once
2
26#include <parcel/json.h>
27
28#include <commons/display_info.hpp>
29#include <commons/fixed_string.hpp>
30#include <commons/types.hpp>
31
32#include <algorithm>
33#include <array>
34#include <cstddef>
35#include <cstdint>
36#include <string>
37#include <string_view>
38
39namespace parcel {
40
41#if defined(COMMONS_HAS_INT128)
43using comms::u128;
44
46using comms::i128;
47#endif
48
63using comms::FixedString;
64
75using DisplayInfo = comms::DisplayInfo;
76
90template <std::string_view const&... Parts>
91struct id_join {
92 static constexpr std::size_t total_size = (Parts.size() + ... + 0);
93 static constexpr auto buf = [] {
94 std::array<char, total_size> r{};
95 std::size_t off = 0;
96 ((std::ranges::copy(Parts, r.begin() + off), off += Parts.size()), ...);
97 return r;
98 }();
99 static constexpr std::string_view value{buf.data(), buf.size()};
100};
101
103template <std::string_view const&... Parts>
104inline constexpr std::string_view id_join_v = id_join<Parts...>::value;
105
126template <FixedString... Parts>
128 static constexpr std::size_t total_size = (Parts.view().size() + ... + 0);
129 static constexpr auto buf = [] {
130 std::array<char, total_size> r{};
131 std::size_t off = 0;
132 ((std::ranges::copy(Parts.view(), r.begin() + off), off += Parts.view().size()), ...);
133 return r;
134 }();
135 static constexpr std::string_view value{buf.data(), buf.size()};
136};
137
139template <FixedString... Parts>
140inline constexpr std::string_view id_join_lit_v = id_join_lit<Parts...>::value;
141
161template <FixedString Prefix, std::string_view const& Tail>
163 static constexpr std::size_t total_size = Prefix.view().size() + Tail.size();
164 static constexpr auto buf = [] {
165 std::array<char, total_size> r{};
166 std::ranges::copy(Prefix.view(), r.begin());
167 std::ranges::copy(Tail, r.begin() + Prefix.view().size());
168 return r;
169 }();
170 static constexpr std::string_view value{buf.data(), buf.size()};
171};
172
174template <FixedString Prefix, std::string_view const& Tail>
175inline constexpr std::string_view prefixed_id_v = prefixed_id<Prefix, Tail>::value;
176
177} // namespace parcel
comms::DisplayInfo DisplayInfo
Display info attached to a cell or descriptor — re-exported from comms::DisplayInfo.
Definition common.h:75
constexpr std::string_view id_join_lit_v
Convenience alias yielding the joined std::string_view.
Definition common.h:140
constexpr std::string_view prefixed_id_v
Convenience alias yielding the joined std::string_view.
Definition common.h:175
constexpr std::string_view id_join_v
Convenience alias yielding the joined std::string_view.
Definition common.h:104
nlohmann::json typedef shared across cell types.
Compile-time concatenation of FixedString literals into a single std::string_view with static storage...
Definition common.h:127
Compile-time concatenation of std::string_view references into a single std::string_view with static ...
Definition common.h:91
Compile-time concatenation of a FixedString literal prefix with a std::string_view reference tail int...
Definition common.h:162