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()
28 ->
decltype(
static_cast<
void>(
sizeof(T)),
false) {
29 return std::is_aggregate_v<T>;
32template <
typename ,
typename... Args>
33constexpr auto IsDefinedAndAggregate(Args...) ->
bool {
44#define USERVER_IMPL_STRUCT_MAP(r, data, elem)
45 std::forward<OtherDeps>(other).elem,
48#define USERVER_IMPL_MAKE_FROM_SUPERSET(Self, ...)
49 template <typename OtherDeps>
50 static Self MakeFromSupersetImpl(
51 OtherDeps&& other, USERVER_NAMESPACE
::utils::impl::InternalTag) {
52 return {BOOST_PP_SEQ_FOR_EACH
(USERVER_IMPL_STRUCT_MAP
, BOOST_PP_EMPTY
(),
53 USERVER_IMPL_VARIADIC_TO_SEQ
(__VA_ARGS__))};
57#define USERVER_IMPL_STRUCT_SUBSET_MAP(r, data, elem)
59 decltype(data::elem) elem;
62#define USERVER_IMPL_STRUCT_SUBSET_REF_MAP(r, data, elem)
64 std::add_const_t<decltype(data::elem)>& elem;
74#define USERVER_ALLOW_CONVERSIONS_TO_SUBSET()
78 USERVER_NAMESPACE
::utils::impl::IsDefinedAndAggregate<Other>(), int>
80 operator
Other() const& {
81 return Other::MakeFromSupersetImpl(
82 *this, USERVER_NAMESPACE
::utils::impl::InternalTag{});
88 USERVER_NAMESPACE
::utils::impl::IsDefinedAndAggregate<Other>(), int>
91 return Other::MakeFromSupersetImpl(
92 std::move(*this), USERVER_NAMESPACE
::utils::impl::InternalTag{});
95 friend struct USERVER_NAMESPACE
::utils::impl::RequireSemicolon
117#define USERVER_DEFINE_STRUCT_SUBSET(SubsetStruct, OriginalStruct, ...)
118 struct SubsetStruct {
119 BOOST_PP_SEQ_FOR_EACH
(USERVER_IMPL_STRUCT_SUBSET_MAP
, OriginalStruct,
120 USERVER_IMPL_VARIADIC_TO_SEQ
(__VA_ARGS__))
122 USERVER_IMPL_MAKE_FROM_SUPERSET
(SubsetStruct, __VA_ARGS__)
153#define USERVER_DEFINE_STRUCT_SUBSET_REF(SubsetStructRef, OriginalStruct, ...)
154 struct SubsetStructRef {
155 BOOST_PP_SEQ_FOR_EACH
(USERVER_IMPL_STRUCT_SUBSET_REF_MAP
, OriginalStruct,
156 USERVER_IMPL_VARIADIC_TO_SEQ
(__VA_ARGS__))
159 USERVER_NAMESPACE
::utils::impl::NonMovable _impl_non_movable{
160 USERVER_NAMESPACE
::utils::impl::InternalTag{}};
162 USERVER_IMPL_MAKE_FROM_SUPERSET
(SubsetStructRef, __VA_ARGS__)