mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 11:55:30 +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
|
||||
std::string str() const;
|
||||
|
||||
// Transform the semantice values 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 F> auto transform(F f) const -> vector<typename std::remove_const<decltype(f(SemanticValue()))>::type>;
|
||||
template <typename T> auto transform(size_t beg = 0, size_t end = -1) const -> vector<T>;
|
||||
// Transform the semantice value vector to another vector
|
||||
template <typename T>
|
||||
vector<T> transform(size_t beg = 0, size_t end = -1) const;
|
||||
}
|
||||
```
|
||||
|
||||
|
11
peglib.h
11
peglib.h
@ -209,6 +209,12 @@ struct SemanticValues : protected std::vector<SemanticValue>
|
||||
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>
|
||||
auto transform(F f) const -> vector<typename std::remove_const<decltype(f(SemanticValue()))>::type> {
|
||||
vector<typename std::remove_const<decltype(f(SemanticValue()))>::type> r;
|
||||
@ -227,11 +233,6 @@ struct SemanticValues : protected std::vector<SemanticValue>
|
||||
}
|
||||
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