types::list< typename std::remove_cv<typename Iterable::iterator::value_type>::type> sorted(Iterable const &seq, C const &cmp) { types::list<typename std::remove_cv< typename Iterable::iterator::value_type>::type> out(seq.begin(), seq.end()); std::sort(out.begin(), out.end(), cmp); return out; }
inline std::string join(const std::string& separator, const Iterable& i) { std::string result; typename Iterable::const_iterator iterator = i.begin(); while (iterator != i.end()) { result += stringify(*iterator); if (++iterator != i.end()) { result += separator; } } return result; }
std::string join(const Iterable & iterable, const std::string & separator) { std::stringstream stream; for (auto it = iterable.begin(); it != iterable.end(); ++it) { stream << *it; if (it != --iterable.end()) stream << separator; } return stream.str(); }
/// Check if 0 or more values are equal. /// /// \param state Lua state /// \param indices Indices of values to compare template <typename Iterable> inline bool equal(State* state, const Iterable& indices) { auto it = indices.begin(); auto end = indices.end(); if (it == end) return true; int cmp_index = *it++; while (it != end) { int index = *it++; if (!equal(state, cmp_index, index)) return false; cmp_index = index; } return true; }
long len_set(Iterable const &s) { return std::set<typename std::iterator_traits< typename Iterable::iterator>::value_type>(s.begin(), s.end()).size(); }