feat(math): add operator field to expressions

This commit is contained in:
2026-11-01 05:35:58 +01:00
parent 09d23cd568
commit b482010c5d
+12 -6
View File
@@ -14,7 +14,12 @@ struct expression_tag {};
template <typename E, typename Op>
struct unary_expression : expression_tag {
E expr;
E expr;
Op op;
template <typename EFwd = E, typename OpFwd = Op, typename = std::enable_if_t<std::is_constructible_v<E, EFwd>>>
unary_expression(EFwd&& expr, OpFwd&& op = Op{}) // NOLINT
: expr(std::forward<EFwd>(expr)), op(std::forward<OpFwd>(op)) {}
constexpr auto shape() const { return expr.shape(); }
@@ -23,12 +28,13 @@ struct unary_expression : expression_tag {
template <typename L, typename R, typename Op>
struct binary_expression : expression_tag {
L lhs;
R rhs;
L lhs;
R rhs;
Op op;
template <typename LFwd = L, typename RFwd = R>
binary_expression(LFwd&& lhs, RFwd&& rhs)
: lhs(std::forward<LFwd>(lhs)), rhs(std::forward<RFwd>(rhs)) {}
template <typename LFwd = L, typename RFwd = R, typename OpFwd = Op>
binary_expression(LFwd&& lhs, RFwd&& rhs, OpFwd&& op = Op{})
: lhs(std::forward<LFwd>(lhs)), rhs(std::forward<RFwd>(rhs)), op(std::forward<OpFwd>(op)) {}
constexpr auto shape() const { return Op::shape(lhs, rhs); }