[gnome-system-monitor] Add generic function to join elements of a collection.
- From: Benoît Dejean <bdejean src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-system-monitor] Add generic function to join elements of a collection.
- Date: Fri, 28 Oct 2016 13:45:44 +0000 (UTC)
commit 1ac93e7fe5bdf7c7d43066367a8bcf290404815d
Author: Benoît Dejean <bdejean gmail com>
Date: Fri Oct 28 15:19:33 2016 +0200
Add generic function to join elements of a collection.
src/util.h | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
---
diff --git a/src/util.h b/src/util.h
index a389b35..8d5fb3d 100644
--- a/src/util.h
+++ b/src/util.h
@@ -136,6 +136,24 @@ namespace procman
NonCopyable& operator=(const NonCopyable&) /* = delete */;
};
+
+ // join the elements of c with sep
+ template<typename C, typename S>
+ auto join(const C& c, const S& sep) -> decltype(c[0] + sep)
+ {
+ decltype(c[0] + sep) r;
+ bool first = true;
+
+ for(const auto& e : c) {
+ if (!first) {
+ r += sep;
+ }
+ first = false;
+ r += e;
+ }
+
+ return r;
+ }
}
#endif /* _GSM_UTIL_H_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]