Вы можете очень легко создать пользовательскую политику, которая делает то, что вы хотите:
template <typename ValueType>
struct really_strict_real_policies : boost::spirit::x3::strict_real_policies<ValueType>
{
static bool const allow_leading_dot = false;
static bool const allow_trailing_dot = false;
};
Полный пример (Running on WandBox)
#include <iostream>
#include <boost/spirit/home/x3.hpp>
template <typename ValueType>
struct really_strict_real_policies : boost::spirit::x3::strict_real_policies<ValueType>
{
static bool const allow_leading_dot = false;
static bool const allow_trailing_dot = false;
};
template <typename Parser>
void parse(const std::string& input, const Parser& parser, bool expected)
{
std::string::const_iterator iter=input.begin(), end=input.end();
bool result = boost::spirit::x3::parse(iter,end,parser);
if((result && (iter==end))==expected)
std::cout << "Yay" << std::endl;
}
int main()
{
boost::spirit::x3::real_parser<double, really_strict_real_policies<double> > const really_strict_double = {};
parse(".2",really_strict_double,false);
parse("2.",really_strict_double,false);
parse("2.2",really_strict_double,true);
}
большое спасибо, это даже больше, чем я ожидал, я думал, Я бы выполнил свой собственный двойной парсер – Exagon