summaryrefslogtreecommitdiff
path: root/tiger-compiler/lib/misc/separator.hxx
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/lib/misc/separator.hxx
add: added projectsHEADmain
Diffstat (limited to 'tiger-compiler/lib/misc/separator.hxx')
-rw-r--r--tiger-compiler/lib/misc/separator.hxx55
1 files changed, 55 insertions, 0 deletions
diff --git a/tiger-compiler/lib/misc/separator.hxx b/tiger-compiler/lib/misc/separator.hxx
new file mode 100644
index 0000000..103b78d
--- /dev/null
+++ b/tiger-compiler/lib/misc/separator.hxx
@@ -0,0 +1,55 @@
+/**
+ ** \file misc/separator.hxx
+ ** \brief Output containers with a separator between items.
+ */
+
+#pragma once
+
+#include <ostream>
+
+#include <misc/deref.hh>
+#include <misc/separator.hh>
+
+namespace misc
+{
+ template <class C, class S>
+ inline separator<C, S>::separator(const C& c, const S& s)
+ : container_(c)
+ , separator_(s)
+ {}
+
+ template <class C, typename S>
+ inline std::ostream& separator<C, S>::operator()(std::ostream& o) const
+ {
+ for (auto i = container_.begin(); i != container_.end(); ++i)
+ {
+ if (i != container_.begin())
+ o << separator_;
+ o << deref << *i;
+ }
+ return o;
+ }
+
+ template <class C, typename S>
+ separator<C, S> separate(const C& c, const S& s)
+ {
+ return separator<C, S>(c, s);
+ }
+
+ template <class C> separator<C, char> separate(const C& c)
+ {
+ return separate(c, '\n');
+ }
+
+ template <class C, typename S>
+ inline std::ostream& operator<<(std::ostream& o, const separator<C, S>& s)
+ {
+ return s(o);
+ }
+
+ template <class A, typename B>
+ inline std::ostream& operator<<(std::ostream& o, const std::pair<A, B>& p)
+ {
+ return o << p.first << p.second;
+ }
+} // namespace misc