|
Boost : |
Subject: Re: [boost] [xpressive] capture float?
From: Eric Niebler (eniebler_at_[hidden])
Date: 2014-07-23 19:57:25
On 7/23/2014 3:47 PM, Greg Rubino wrote:
> On Wed, Jul 23, 2014 at 4:07 PM, Greg Rubino wrote:
>> Hi all,
>>
>> I'm trying to capture a float with xpressive and put it into a local map.
>> As a simplified example, I tried just pushing the matched pattern to a
>> float and the result is always a float containing '0'.
>>
>> namespace xpr = boost::xpressive;
>>
>> std::map<float, std::string> l_floatOperMap;
>>
>> xpr::sregex l_relation = xpr::as_xpr("<=") | ">=" | "<" | ">");
>> l_floatRestriction =
>> !(xpr::s1 = l_relation) >> (xpr::s2 = (+xpr::_d >> '.' >>
>> +xpr::_d))
>> [xpr::ref(l_floatOperMap)[xpr::as<float>(xpr::s2)] =
>> xpr::as<std::string>(xpr::s1)];
>>
>>
>> However, when I go to print the contents of l_floatOperMap, it contains
>> only the tuple (0, ""). Is it something I'm doing wrong? It seems like
>> this should work to me.
>>
>>
> I neglected to mention that I am actually doing the very same thing with
> uint32_t and it works fine.
Works for me. This program:
#include <map>
#include <iostream>
#include <boost/xpressive/xpressive.hpp>
#include <boost/xpressive/regex_actions.hpp>
int main()
{
namespace xpr = boost::xpressive;
std::map<float, std::string> l_floatOperMap;
xpr::sregex l_relation = xpr::as_xpr("<=") | ">=" | "<" | ">";
xpr::sregex l_floatRestriction =
!(xpr::s1 = l_relation) >>
(xpr::s2 = (+xpr::_d >> '.' >> +xpr::_d))
[
xpr::ref(l_floatOperMap)[xpr::as<float>(xpr::s2)] =
xpr::as<std::string>(xpr::s1)
];
std::string str = ">3.14";
if(xpr::regex_match(str, l_floatRestriction))
{
for(auto p : l_floatOperMap)
{
std::cout << "(" << p.first << ", " << p.second << ")"
<< std::endl;
}
}
}
Gives me this expected output:
(3.14, >)
Maybe you could send a complete repro?
Thanks,
Eric
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk