feat(math): add operator field to expressions
This commit is contained in:
@@ -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); }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user