Boost logo

Boost Users :

Subject: [Boost-users] [lambda] extract a constant subexpression by introspection
From: alfC (alfredo.correa_at_[hidden])
Date: 2010-05-21 21:21:44


Hello,

 I have a lambda expression that is suppoalways constructed as

 [some lambda expression] / ( _1 - c);

where c is a double constant, for example c = 3.14.

What I need is a function that given the expression returns the
internal value of c, if that is possible:

template<class LambdaExp>
double c(LambdaExp expr){
  ...
  return c in expr assuming that expr has the form [...]/(_1 - c)
}

The function may throw an exception or whatever if the expr is not of
the form [...]/(_1 - c)

Some additional infomation that maybe useful to simplify the solution:
the lambda expression returns a double, _1 is meant to be a
placeholder for double.

optional feature: Also it would be ideal if the function could also
recognize *simple* alternative expressions like [..]/(_1 + k) (and
return -k) or [...]/( k + _1) (and return -k).

Solutions using other lambda-like libraries are welcomed too.
Thank you,
Alfredo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net