
I am trying to use a placeholder object for the check function in an xpressive regex. The error I usually get is "error C2064: term does not evaluate to a function taking 1 arguments" Please see my example below that uses the three_or_six user-defined assertion as described at http://www.boost.org/doc/libs/1_51_0/doc/html/xpressive/user_s_guide.html#bo.... I am using boost 1.51 and Visual Studio 2010 Express. This is a contrived example; the real reason I am trying to do this is because my assertion has state that is not known at the time the regex is compiled. In the interim I have worked around it by using static variables instead of placeholders but that makes for more brittle code than I would like. Also, is there any way to reuse the match_results objects that are created by the iterator syntax? Thanks, Michael Mitchell //Inspired by https://groups.google.com/forum/#!topic/boost-list/hTBAT7KMgd4 #include <iostream> #include <boost/xpressive/regex_actions.hpp> #include <boost/xpressive/xpressive_static.hpp> using namespace std; using namespace boost::xpressive; // A predicate that is true IFF a sub-match is // either 3 or 6 characters long. struct three_or_six { bool operator()(ssub_match const &sub) const { return sub.length() == 3 || sub.length() == 6; } }; int main(int argc, char* argv[]) { int cnt = 0; string a_str("a_aaaaa___a_aa_aaa_"); // match words of 3 characters or 6 characters (this works). sregex expr1 = (bow >> +_w >> eow)[ check(three_or_six()) ] ; placeholder<three_or_six> tos_ph; sregex expr2 = (bow >> +_w >> eow)[ check(tos_ph) ] ; // The above does not work (error C2064: term does not evaluate to a function taking 1 arguments) placeholder<three_or_six*> tos_ptr_ph; sregex expr3 = (bow >> +_w >> eow)[ check(*tos_ptr_ph) ] ; // The above does not work (error 2676: binary '&&' : 'three_or_six' does not define this operator or a converstion to a type acceptable to the predefinied operator) sregex_iterator iter1(a_str.begin(), a_str.end(), expr1); three_or_six tos; sregex_iterator iter2(a_str.begin(), a_str.end(), expr2, let(tos_ph = tos)); three_or_six* tos_ptr = new three_or_six(); sregex_iterator iter3(a_str.begin(), a_str.end(), expr3, let(tos_ptr_ph = tos_ptr)); return 0; }