|
Boost : |
From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2003-12-10 11:07:23
Hi!
I'm working on a simple script interpreter (using Spirit) that should feature overloaded
operators as in:
BEGIN sample script:
----------------------
scalar a = 1 ;
scalar b = 2 ;
scalar c = a + b ; // scalar operator+(scalar,scalar)
vector2 p = (1,2) ;
vector2 q = (3,4) ;
vector2 r = p + q ; // vector2 operator+( vector2,vector2)
scalar d = p * q ; // scalar operator*(vector2,vector2)
vector2 s = p * b ; // vector2 operator*(vector2,scalar)
---------------------
END Sample script
Spirit question:
¿Is there a direct way to support overload resolution in Spirit?
That is, how do I attach a _set_ of semantics actions to the operators (+,-) depending on the
combination of the "type" atttribute of the operands?
Variant Question:
Assuming the above cannot be directly expressed using Spirit, I can use variant<> to hold the
operand values (and types), but then, I would need a double-dispatch visitor that I can apply to
both operands, as in:
struct plus
{
int operator+( int, int);
vect operator+( vect, vect);
} ;
void od_plus()
{
variant<int,vect> l = .... ,r = .... ;
apply_visitor(plus,l,r);
}
TIA
Fernando Cacciola
SciSoft
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk