10#include <boost/preprocessor/empty.hpp>
11#include <boost/preprocessor/seq/for_each.hpp>
13#include <userver/utils/impl/boost_variadic_to_seq.hpp>
14#include <userver/utils/impl/internal_tag.hpp>
16USERVER_NAMESPACE_BEGIN
18namespace utils::impl {
20struct RequireSemicolon;
22struct NonMovable
final {
23 constexpr explicit NonMovable(InternalTag)
noexcept {}
27constexpr auto IsDefinedAndAggregate() ->
decltype(
static_cast<
void>(
sizeof(T)),
false) {
28 return std::is_aggregate_v<T>;
31template <
typename ,
typename... Args>
32constexpr auto IsDefinedAndAggregate(Args...) ->
bool {
43#define USERVER_IMPL_STRUCT_MAP(r, data, elem) std::forward<OtherDeps>(other).elem,
46#define USERVER_IMPL_MAKE_FROM_SUPERSET(Self, ...)
47 template <typename OtherDeps>
48 static Self MakeFromSupersetImpl(OtherDeps&& other, USERVER_NAMESPACE
::utils::impl::InternalTag) {
49 return {BOOST_PP_SEQ_FOR_EACH
(
50 USERVER_IMPL_STRUCT_MAP
, BOOST_PP_EMPTY
(), USERVER_IMPL_VARIADIC_TO_SEQ
(__VA_ARGS__)
55#define USERVER_IMPL_STRUCT_SUBSET_MAP(r, data, elem)
57 decltype(data::elem) elem;
60#define USERVER_IMPL_STRUCT_SUBSET_REF_MAP(r, data, elem)
62 std::add_const_t<decltype(data::elem)>& elem;
72#define USERVER_ALLOW_CONVERSIONS_TO_SUBSET()
75 std::enable_if_t<USERVER_NAMESPACE
::utils::impl::IsDefinedAndAggregate<Other>(), int> Enable = 0
>
76 operator
Other() const& {
77 return Other::MakeFromSupersetImpl(*this, USERVER_NAMESPACE
::utils::impl::InternalTag{});
82 std::enable_if_t<USERVER_NAMESPACE
::utils::impl::IsDefinedAndAggregate<Other>(), int> Enable = 0
>
84 return Other::MakeFromSupersetImpl(std::move(*this), USERVER_NAMESPACE
::utils::impl::InternalTag{});
87 friend struct USERVER_NAMESPACE
::utils::impl::RequireSemicolon
109#define USERVER_DEFINE_STRUCT_SUBSET(SubsetStruct, OriginalStruct, ...)
110 struct SubsetStruct {
111 BOOST_PP_SEQ_FOR_EACH
(
112 USERVER_IMPL_STRUCT_SUBSET_MAP
,
114 USERVER_IMPL_VARIADIC_TO_SEQ
(__VA_ARGS__)
117 USERVER_IMPL_MAKE_FROM_SUPERSET
(SubsetStruct, __VA_ARGS__)
148#define USERVER_DEFINE_STRUCT_SUBSET_REF(SubsetStructRef, OriginalStruct, ...)
149 struct SubsetStructRef {
150 BOOST_PP_SEQ_FOR_EACH
(
151 USERVER_IMPL_STRUCT_SUBSET_REF_MAP
,
153 USERVER_IMPL_VARIADIC_TO_SEQ
(__VA_ARGS__)
157 USERVER_NAMESPACE
::utils::impl::NonMovable _impl_non_movable{USERVER_NAMESPACE
::utils::impl::InternalTag{}};
159 USERVER_IMPL_MAKE_FROM_SUPERSET
(SubsetStructRef, __VA_ARGS__)