Simplified API.

This commit is contained in:
yhirose 2015-06-16 01:01:02 -04:00
parent c9b5f0ac3b
commit 20c303d6e9
2 changed files with 9 additions and 9 deletions

View File

@ -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;
}
```

View File

@ -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>(); });
}
};
/*