MCPcopy Create free account
hub / github.com/boostorg/spirit / parse_complex

Function parse_complex

example/x3/complex_number.cpp:29–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27{
28 template <typename Iterator>
29 bool parse_complex(Iterator first, Iterator last, std::complex<double>& c)
30 {
31 using boost::spirit::x3::double_;
32 using boost::spirit::x3::_attr;
33 using boost::spirit::x3::phrase_parse;
34 using boost::spirit::x3::ascii::space;
35
36 double rN = 0.0;
37 double iN = 0.0;
38 auto fr = [&](auto& ctx){ rN = _attr(ctx); };
39 auto fi = [&](auto& ctx){ iN = _attr(ctx); };
40
41 bool r = phrase_parse(first, last,
42
43 // Begin grammar
44 (
45 '(' >> double_[fr]
46 >> -(',' >> double_[fi]) >> ')'
47 | double_[fr]
48 ),
49 // End grammar
50
51 space);
52
53 if (!r || first != last) // fail if we did not get a full match
54 return false;
55 c = std::complex<double>(rN, iN);
56 return r;
57 }
58}
59
60////////////////////////////////////////////////////////////////////////////

Callers 1

mainFunction · 0.70

Calls 2

_attrFunction · 0.85
phrase_parseFunction · 0.50

Tested by

no test coverage detected