Consider the following example.
#include <print>
#include <string>
#include <boost/parser/parser.hpp>
namespace bp = boost::parser;
int main(int argc, char *argv[]) {
auto input = std::string{"ab"};
auto res = std::string();
const auto result = bp::parse(
input
, (bp::char_ >> bp::char_)
, res
);
if (result) {
std::print("Parse successful\n");
std::print("{}\n", res);
} else {
std::print("Parse failed\n");
}
}
It outputs
Now consider this change
#include <print>
#include <ranges>
#include <string>
#include <boost/parser/parser.hpp>
#include <boost/parser/transcode_view.hpp>
namespace bp = boost::parser;
namespace rs = std::ranges;
int main(int argc, char *argv[]) {
auto input = std::u32string{U"ab"};
auto res = std::u32string();
const auto result = bp::parse(
input
, (bp::char_ >> bp::char_)
, res
);
if (result) {
std::print("Parse successful\n");
std::print("{}\n", res | bp::as_utf8 | rs::to<std::string>());
} else {
std::print("Parse failed\n");
}
}
It outputs
The issue is here:
if constexpr (detail::is_nope_v<attr_t>) {
// nothing to do
} if constexpr (
(!out_container ||
!std::is_same_v<just_x, just_out>) &&
std::is_assignable_v<just_out &, just_x &&> &&
(!std::is_same_v<just_out, std::string> ||
!std::is_integral_v<just_x>)) {
detail::assign(out, std::move(x));
} else {
detail::move_back(
out, std::move(x), detail::gen_attrs(flags));
}
This code adds to a string only if it is an std::string. Otherwise, it assigns every character to the same string.
Consider the following example.
It outputs
Now consider this change
It outputs
The issue is here:
This code adds to a string only if it is an
std::string. Otherwise, it assigns every character to the same string.