Copyright Matus Chochlik. Distributed under the Boost Software License, Version 1.0. See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
#include <iostream>
#include <sstream>
struct my_struct {
bool b{false};
char c{'\0'};
double d{0.0};
long l{};
std::string s{};
unsigned u{0U};
};
template <identifier_t Id>
constexpr auto
data_member_mapping(type_identity<my_struct>, selector<Id>) noexcept {
using S = my_struct;
return make_data_member_mapping<
S,
bool,
char,
double,
long,
std::string,
unsigned>(
{"b", &S::b},
{"c", &S::c},
{"d", &S::d},
{"i", &S::i},
{"l", &S::l},
{"s", &S::s},
{"u", &S::u});
}
void baz(const my_struct& instance) {
std::cout << instance.b;
std::cout << instance.c;
std::cout << instance.d;
std::cout << instance.i.name();
std::cout << instance.l;
std::cout << instance.s;
std::cout << instance.u;
std::cout << std::endl;
}
void bar(std::istream& data) {
istream_data_source source(data);
string_deserializer_backend backend(source);
my_struct instance;
auto member_map = map_data_members(instance);
baz(instance);
}
void foo(const my_struct& instance) {
std::stringstream data;
ostream_data_sink sink(data);
string_serializer_backend backend(sink);
auto member_map = map_data_members(instance);
bar(data);
}
}
auto main() -> int {
my_struct x;
x.b = true;
x.c = '2';
x.d = 3.4;
x.l = 7777777L;
x.s = "eight";
x.u = 90U;
foo(x);
return 0;
}
static constexpr auto as_bytes(basic_span< T, P, S > spn) noexcept -> basic_block< std::is_const_v< T >>
Converts a span into a basic_block.
Definition: block.hpp:39
Common code is placed in this namespace.
Definition: eagine.hpp:21
static constexpr auto view(T *addr, S size) noexcept -> const_span< T >
Creates a view starting at the specified pointer and specified length.
Definition: span.hpp:458
auto deserialize(T &value, Backend &backend) -> std::enable_if_t< std::is_base_of_v< deserializer_backend, Backend >, deserialization_errors >
Deserializes a value with the specified serialization backend.
Definition: read.hpp:475
auto serialize(T &value, Backend &backend) -> std::enable_if_t< std::is_base_of_v< serializer_backend, Backend >, serialization_errors >
Serializes a value with the specified serialization backend.
Definition: write.hpp:480
basic_identifier< 10, 6, default_identifier_char_set, identifier_t > identifier
Default identifier type used throughout the project.
Definition: identifier.hpp:346