mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
Simplified API.
This commit is contained in:
parent
c9b5f0ac3b
commit
20c303d6e9
@ -103,10 +103,9 @@ struct SemanticValues : protected std::vector<SemanticValue>
|
|||||||
// Get token
|
// Get token
|
||||||
std::string str() const;
|
std::string str() const;
|
||||||
|
|
||||||
// Transform the semantice values vector to another vector
|
// Transform the semantice value vector to another vector
|
||||||
template <typename F> auto transform(size_t beg, size_t end, F f) const -> vector<typename std::remove_const<decltype(f(SemanticValue()))>::type>;
|
template <typename T>
|
||||||
template <typename F> auto transform(F f) const -> vector<typename std::remove_const<decltype(f(SemanticValue()))>::type>;
|
vector<T> transform(size_t beg = 0, size_t end = -1) const;
|
||||||
template <typename T> auto transform(size_t beg = 0, size_t end = -1) const -> vector<T>;
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
11
peglib.h
11
peglib.h
@ -209,6 +209,12 @@ struct SemanticValues : protected std::vector<SemanticValue>
|
|||||||
return std::string(s, n);
|
return std::string(s, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
auto transform(size_t beg = 0, size_t end = -1) const -> vector<T> {
|
||||||
|
return this->transform(beg, end, [](const SemanticValue& v) { return v.get<T>(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
template <typename F>
|
template <typename F>
|
||||||
auto transform(F f) const -> vector<typename std::remove_const<decltype(f(SemanticValue()))>::type> {
|
auto transform(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;
|
||||||
@ -227,11 +233,6 @@ struct SemanticValues : protected std::vector<SemanticValue>
|
|||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
auto transform(size_t beg = 0, size_t end = -1) const -> vector<T> {
|
|
||||||
return this->transform(beg, end, [](const SemanticValue& v) { return v.get<T>(); });
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user