mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
Removed 'reduce' from SemanticValues.
This commit is contained in:
parent
4d65fc4c56
commit
81d7593ea1
@ -24,6 +24,15 @@ using namespace std;
|
|||||||
// ~_ <- [ \t\r\n]*
|
// ~_ <- [ \t\r\n]*
|
||||||
//
|
//
|
||||||
|
|
||||||
|
template <typename T, typename U, typename F>
|
||||||
|
static U reduce(T i, T end, U val, F f) {
|
||||||
|
if (i == end) {
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
std::tie(val, i) = f(val, i);
|
||||||
|
return reduce(i, end, val, f);
|
||||||
|
};
|
||||||
|
|
||||||
struct ast_node
|
struct ast_node
|
||||||
{
|
{
|
||||||
virtual ~ast_node() = default;
|
virtual ~ast_node() = default;
|
||||||
@ -48,7 +57,7 @@ struct ast_ope : public ast_node
|
|||||||
|
|
||||||
static shared_ptr<ast_node> create(const SemanticValues& sv) {
|
static shared_ptr<ast_node> create(const SemanticValues& sv) {
|
||||||
assert(!sv.empty());
|
assert(!sv.empty());
|
||||||
return SemanticValues::reduce(
|
return reduce(
|
||||||
sv.begin() + 1,
|
sv.begin() + 1,
|
||||||
sv.end(),
|
sv.end(),
|
||||||
sv[0].get<shared_ptr<ast_node>>(),
|
sv[0].get<shared_ptr<ast_node>>(),
|
||||||
|
9
peglib.h
9
peglib.h
@ -220,15 +220,6 @@ struct SemanticValues : protected std::vector<SemanticValue>
|
|||||||
using std::vector<T>::emplace;
|
using std::vector<T>::emplace;
|
||||||
using std::vector<T>::emplace_back;
|
using std::vector<T>::emplace_back;
|
||||||
|
|
||||||
template <typename T, typename U, typename F>
|
|
||||||
static U reduce(T i, T end, U val, F f) {
|
|
||||||
if (i == end) {
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
std::tie(val, i) = f(val, i);
|
|
||||||
return reduce(i, end, val, f);
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
auto map(F f) const -> vector<typename std::remove_const<decltype(f(SemanticValue()))>::type> {
|
auto map(F f) const -> vector<typename std::remove_const<decltype(f(SemanticValue()))>::type> {
|
||||||
vector<typename std::remove_const<decltype(f(SemanticValue()))>::type> r;
|
vector<typename std::remove_const<decltype(f(SemanticValue()))>::type> r;
|
||||||
|
Loading…
Reference in New Issue
Block a user