add requires for function

This commit is contained in:
ulic-youthlic 2025-04-28 13:58:27 +08:00
parent 88b32bd3f0
commit 0534572646
Signed by: youthlic
GPG key ID: 63E86C3C14A0D721

View file

@ -8,7 +8,11 @@ struct BuildMixin {};
template <>
struct BuildMixin<true> {
auto build(this auto&& self) { return self.p1 + self.p2; }
auto build(this auto&& self)
requires requires { self.p1 + self.p2; }
{
return self.p1 + self.p2;
}
};
template <bool enabled>
@ -16,7 +20,9 @@ struct Param1Mixin {};
template <>
struct Param1Mixin<false> {
auto fill_param1(this auto&& self) {
auto fill_param1(this auto&& self)
requires requires { self.p1; }
{
self.p1 = 1;
return Builder<true, std::remove_reference_t<decltype(self)>::param2_v>(
self);
@ -28,7 +34,9 @@ struct Param2Mixin {};
template <>
struct Param2Mixin<false> {
auto fill_param2(this auto&& self) {
auto fill_param2(this auto&& self)
requires requires { self.p2; }
{
self.p2 = 1;
return Builder<std::remove_reference_t<decltype(self)>::param1_v, true>(
self);