From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/lib/misc/separator.hxx | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tiger-compiler/lib/misc/separator.hxx (limited to 'tiger-compiler/lib/misc/separator.hxx') 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 + +#include +#include + +namespace misc +{ + template + inline separator::separator(const C& c, const S& s) + : container_(c) + , separator_(s) + {} + + template + inline std::ostream& separator::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 + separator separate(const C& c, const S& s) + { + return separator(c, s); + } + + template separator separate(const C& c) + { + return separate(c, '\n'); + } + + template + inline std::ostream& operator<<(std::ostream& o, const separator& s) + { + return s(o); + } + + template + inline std::ostream& operator<<(std::ostream& o, const std::pair& p) + { + return o << p.first << p.second; + } +} // namespace misc -- cgit v1.2.3