feat(math): add operator field to expressions

This commit is contained in:
2026-11-01 05:35:58 +01:00
parent 09d23cd568
commit b482010c5d
+9 -3
View File
@@ -15,6 +15,11 @@ struct expression_tag {};
template <typename E, typename Op> template <typename E, typename Op>
struct unary_expression : expression_tag { 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(); } constexpr auto shape() const { return expr.shape(); }
@@ -25,10 +30,11 @@ template <typename L, typename R, typename Op>
struct binary_expression : expression_tag { struct binary_expression : expression_tag {
L lhs; L lhs;
R rhs; R rhs;
Op op;
template <typename LFwd = L, typename RFwd = R> template <typename LFwd = L, typename RFwd = R, typename OpFwd = Op>
binary_expression(LFwd&& lhs, RFwd&& rhs) binary_expression(LFwd&& lhs, RFwd&& rhs, OpFwd&& op = Op{})
: lhs(std::forward<LFwd>(lhs)), rhs(std::forward<RFwd>(rhs)) {} : lhs(std::forward<LFwd>(lhs)), rhs(std::forward<RFwd>(rhs)), op(std::forward<OpFwd>(op)) {}
constexpr auto shape() const { return Op::shape(lhs, rhs); } constexpr auto shape() const { return Op::shape(lhs, rhs); }