私は次の結果を理解しようとしています。テストケースコードは
#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' は double_ に一致し、int_ には一致しませんが、逆の場合は当てはまりません。'12345' は、整数 (int_ ) と浮動小数点 (double_ ) の両方に一致します。double_ - int_ を試してみましたが、「12345」との一致に失敗しました。しかし、私の希望は、最後のテストケース '12345.34' が double_ - int_ に確実に一致することでしたが、結果は一致しませんでした。
なぜそうなのか、整数のみに一致するパーサーと浮動小数点のみに一致する別のパーサーを取得するにはどうすればよいですか (c のように、5.0 は浮動小数点として解釈されます)。