Skip to content

Commit db906c3

Browse files
refactor: Consolidate unary operation application logic into a single apply function
Signed-off-by: FrozenlemonTee <1115306170@qq.com>
1 parent 5e85b09 commit db906c3

1 file changed

Lines changed: 9 additions & 16 deletions

File tree

src/operations/operators.cppm

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,9 @@ constexpr auto apply(Lhs const &lhs, Rhs const &rhs)
138138

139139
template <operation OpTag, primitive_instance Operand,
140140
typename ErrorPayload = policy::error::kind>
141-
constexpr auto apply_unary(Operand const &operand)
141+
constexpr auto apply(Operand const &operand)
142142
-> unary_dispatch_result_t<OpTag, Operand, ErrorPayload> {
143-
using operand_traits = meta::traits<Operand>;
144-
using value_type = typename operand_traits::value_type;
145-
auto const dummy = Operand{value_type{}};
146-
return apply<OpTag, Operand, Operand, ErrorPayload>(operand, dummy);
143+
return apply<OpTag, Operand, Operand, ErrorPayload>(operand, operand);
147144
}
148145

149146
template <operation OpTag, primitive_instance Lhs, underlying_operand Rhs,
@@ -169,37 +166,33 @@ constexpr auto apply(Lhs const &lhs, Rhs const &rhs)
169166
template <primitive_instance Operand, typename ErrorPayload = policy::error::kind>
170167
constexpr auto increment(Operand &operand)
171168
-> unary_dispatch_result_t<Increment, Operand, ErrorPayload> {
172-
using operand_traits = meta::traits<Operand>;
173-
using value_type = typename operand_traits::value_type;
174-
auto const dummy = Operand{value_type{}};
175-
return apply_assign<Increment, Operand, Operand, ErrorPayload>(operand, dummy);
169+
return apply_assign<Increment, Operand, Operand, ErrorPayload>(operand,
170+
operand);
176171
}
177172

178173
template <primitive_instance Operand, typename ErrorPayload = policy::error::kind>
179174
constexpr auto decrement(Operand &operand)
180175
-> unary_dispatch_result_t<Decrement, Operand, ErrorPayload> {
181-
using operand_traits = meta::traits<Operand>;
182-
using value_type = typename operand_traits::value_type;
183-
auto const dummy = Operand{value_type{}};
184-
return apply_assign<Decrement, Operand, Operand, ErrorPayload>(operand, dummy);
176+
return apply_assign<Decrement, Operand, Operand, ErrorPayload>(operand,
177+
operand);
185178
}
186179

187180
template <primitive_instance Operand, typename ErrorPayload = policy::error::kind>
188181
constexpr auto bit_not(Operand const &operand)
189182
-> unary_dispatch_result_t<BitwiseNot, Operand, ErrorPayload> {
190-
return apply_unary<BitwiseNot, Operand, ErrorPayload>(operand);
183+
return apply<BitwiseNot, Operand, ErrorPayload>(operand);
191184
}
192185

193186
template <primitive_instance Operand, typename ErrorPayload = policy::error::kind>
194187
constexpr auto unary_plus(Operand const &operand)
195188
-> unary_dispatch_result_t<UnaryPlus, Operand, ErrorPayload> {
196-
return apply_unary<UnaryPlus, Operand, ErrorPayload>(operand);
189+
return apply<UnaryPlus, Operand, ErrorPayload>(operand);
197190
}
198191

199192
template <primitive_instance Operand, typename ErrorPayload = policy::error::kind>
200193
constexpr auto unary_minus(Operand const &operand)
201194
-> unary_dispatch_result_t<UnaryMinus, Operand, ErrorPayload> {
202-
return apply_unary<UnaryMinus, Operand, ErrorPayload>(operand);
195+
return apply<UnaryMinus, Operand, ErrorPayload>(operand);
203196
}
204197

205198
// Binary arithmetic operations

0 commit comments

Comments
 (0)