summaryrefslogtreecommitdiff
path: root/tiger-compiler/lib/misc/separator.hh
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.hh
add: added projectsHEADmain
Diffstat (limited to 'tiger-compiler/lib/misc/separator.hh')
-rw-r--r--tiger-compiler/lib/misc/separator.hh43
1 files changed, 43 insertions, 0 deletions
diff --git a/tiger-compiler/lib/misc/separator.hh b/tiger-compiler/lib/misc/separator.hh
new file mode 100644
index 0000000..228e4eb
--- /dev/null
+++ b/tiger-compiler/lib/misc/separator.hh
@@ -0,0 +1,43 @@
+/**
+ ** \file misc/separator.hh
+ ** \brief Output containers with a separator between items.
+ */
+
+#pragma once
+
+#include <iosfwd>
+#include <utility>
+
+namespace misc
+{
+ template <class C, typename S> class separator
+ {
+ public:
+ separator(const C& c, const S& s);
+ std::ostream& operator()(std::ostream& o) const;
+
+ private:
+ const C& container_;
+ const S& separator_;
+ };
+
+ /// Shorthand to create separator(c, s).
+ template <class C, typename S>
+ separator<C, S> separate(const C& c, const S& s);
+
+ /// Shorthand to create separator(c, '\n').
+ template <class C> separator<C, char> separate(const C& c);
+
+ /// Output the separator object \a s on \a ostr.
+ template <class C, typename S>
+ inline std::ostream& operator<<(std::ostream& ostr, const separator<C, S>& s);
+
+ /// Output the pair \a p on \a ostr.
+ /// Usefull if you want to to use a std::pair("something", misc::iendl)
+ /// as your separator.
+ template <class A, typename B>
+ inline std::ostream& operator<<(std::ostream& ostr, const std::pair<A, B>& p);
+
+} // namespace misc
+
+#include <misc/separator.hxx>