Skip to content

Commit eb852c8

Browse files
committed
refactor(synchronizer): reduce duplications
1 parent a1662b8 commit eb852c8

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

include/stdsharp/synchronizer.h

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,24 @@ namespace stdsharp
6060
}
6161

6262
public:
63-
template<typename Self, typename SelfT = const Self>
64-
[[nodiscard]] constexpr auto read_with(this const Self&& self, auto&&... args)
65-
requires requires {
66-
forward_cast<SelfT, synchronizer>(self).template write_impl<shared_lock>(
67-
cpp_forward(args)...
68-
);
69-
}
70-
{
71-
return forward_cast<SelfT, synchronizer>(self).template write_impl<shared_lock>(
72-
cpp_forward(args)...
73-
);
74-
}
75-
76-
template<typename Self, typename SelfT = const Self&>
77-
[[nodiscard]] constexpr auto read_with(this const Self& self, auto&&... args)
78-
requires requires {
79-
forward_cast<SelfT, synchronizer>(self).template write_impl<shared_lock>(
80-
cpp_forward(args)...
81-
);
82-
}
83-
{
84-
return forward_cast<SelfT, synchronizer>(self).template write_impl<shared_lock>(
85-
cpp_forward(args)...
86-
);
87-
}
63+
#define STDSHARP_SYNCHRONIZER_READ_WITH(ref) \
64+
template<typename Self, typename SelfT = const Self ref> \
65+
[[nodiscard]] constexpr auto read_with(this const Self ref self, auto&&... args) \
66+
requires requires { \
67+
forward_cast<SelfT, synchronizer>(self).template write_impl<shared_lock>( \
68+
cpp_forward(args)... \
69+
); \
70+
} \
71+
{ \
72+
return forward_cast<SelfT, synchronizer>(self).template write_impl<shared_lock>( \
73+
cpp_forward(args)... \
74+
); \
75+
}
76+
77+
STDSHARP_SYNCHRONIZER_READ_WITH(&)
78+
STDSHARP_SYNCHRONIZER_READ_WITH(&&)
79+
80+
#undef STDSHARP_SYNCHRONIZER_READ_WITH
8881

8982
template<typename Self, typename SelfT = const Self&>
9083
[[nodiscard]] constexpr auto write_with(this Self&& self, auto&&... args)

0 commit comments

Comments
 (0)