की वृद्धि भावना क्यूई न्यूमेरिक पार्सिंग मैं निम्नलिखित परिणाम को समझने की कोशिश कर रहा हूं। परीक्षण का मामला कोडपूर्णांक और फ्लोटिंग पॉइंट्स
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/variant/recursive_variant.hpp>
#include <boost/spirit/home/support/context.hpp>
#include <boost/spirit/home/phoenix.hpp>
#include <boost/foreach.hpp>
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <vector>
namespace sp = boost::spirit;
namespace qi = boost::spirit::qi;
using namespace boost::spirit::ascii;
namespace fusion = boost::fusion;
namespace phoenix = boost::phoenix;
using phoenix::at_c;
using phoenix::push_back;
using phoenix::bind;
template <typename P>
void test_parser(
char const* input, P const& p, bool full_match = true)
{
using boost::spirit::qi::parse;
char const* f(input);
char const* l(f + strlen(f));
if (parse(f, l, p) && (!full_match || (f == l)))
std::cout << "ok" << std::endl;
else
std::cout << "fail" << std::endl;
}
int main() {
test_parser("+12345", qi::int_); //Ok
test_parser("+12345", qi::double_ - qi::int_); //failed, as expected
test_parser("+12345.34", qi::int_); // failed, as expected
test_parser("+12345.34", qi::double_ - qi::int_); //failed but it should be Ok!
};
है प्रेरणा यहाँ है कि मैं नंबर '12345' पूर्णांक के रूप में और कभी नहीं के रूप में चल अंक मिलान करना चाहते हैं। '12345.34' डबल_ से मेल खाता है और कभी भी int_ नहीं होगा लेकिन पारस्परिक मामला सत्य नहीं है; '12345' दोनों पूर्णांक (int_) और फ़्लोटिंग पॉइंट (double_) से मेल खाता है। मैंने double_ - int_ की कोशिश की और यह '12345' से मेल खाने में सफलतापूर्वक विफल रहा। हालांकि मेरी आशा थी कि अंतिम टेस्ट केस '12345.34' सकारात्मक रूप से डबल_ - int_ से मेल खाता है, लेकिन परिणाम जो मुझे मिलता है वह मेल नहीं हो पाता है।
क्यों यह इतना है, और मैं कैसे एक पार्सर कि केवल पूर्णांकों से मेल खाता है और दूसरा वह केवल अस्थायी अंक से मेल खाता है मिलता है डबल के साथ (जैसे ग में, 5.0 चल बिन्दु रूप में दर्शाया जाएगा)
+1 यह एक बेहतर समाधान है। – academicRobot
धन्यवाद, यह सही काम करता है – lurscher