]> git.tdb.fi Git - builder.git/blobdiff - source/booleanevaluator.cpp
Capture value evaluation function by value
[builder.git] / source / booleanevaluator.cpp
index 6891abceff9a8088db506c6ea1388664830fb4f1..b7c399f9cbc97c58384f0a732c8a6bf1accdc797 100644 (file)
@@ -1,10 +1,12 @@
 #include <stdexcept>
+#include <msp/strings/format.h>
 #include "booleanevaluator.h"
 
 using namespace std;
+using namespace Msp;
 
 BooleanEvaluator::BooleanEvaluator(const ValueFunction &f):
-       func([&f](const string &value, const string *){ return f(value); }),
+       func([f](const string &value, const string *){ return f(value); }),
        ops("&|!")
 { }
 
@@ -51,7 +53,7 @@ bool BooleanEvaluator::evaluate(const string &str)
                        else if(ops.find(*i)!=string::npos)
                                push_op(*i);
                        else
-                               throw runtime_error("syntax error at "+string(1, *i));
+                               throw runtime_error(format("syntax error at %c", *i));
                }
        }
 
@@ -67,7 +69,7 @@ bool BooleanEvaluator::evaluate(const string &str)
 void BooleanEvaluator::push_op(char op)
 {
        if(last_was_op!=is_unary(op))
-               throw runtime_error("syntax error at "+string(1, op));
+               throw runtime_error(format("syntax error at %c", op));
        // TODO Disallow mixing of ! and =/^
        if(is_logic(op) && !var_stack.empty())
                value_stack.push_back(pop_value());