简体   繁体   中英

C++ functor library for evaluating mathematical/arithmetic expressions

Does anyone know of a library that allows you to do something like this?

std::transform(vecA.begin(), vecA.end(), 
               vecB.begin(), 
               vecOutput.begin(), 
               // run-time specified expression 
               magic_functor<float>("exp(a/(b+3))") 
);

Where magic_functor is the library-provided functor and a and b are iterated through vecA and vecB.

I could come up with something myself (and would have a lot of fun doing so), but it's probably better to avoid reinventing the wheel (also my boss would kill me). Have spent some time searching the web, but can't really find anything that fits the bill.

It needs to be flexible and fast, so a functor approach that only parses the string once (eg creates an execution stack internally on construction) would be ideal, but am open to other solutions.

Several options (need some work and won't work “out of the box”):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM