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

View File

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