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.hh | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tiger-compiler/lib/misc/separator.hh (limited to 'tiger-compiler/lib/misc/separator.hh') 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 +#include + +namespace misc +{ + template 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 + separator separate(const C& c, const S& s); + + /// Shorthand to create separator(c, '\n'). + template separator separate(const C& c); + + /// Output the separator object \a s on \a ostr. + template + inline std::ostream& operator<<(std::ostream& ostr, const separator& 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 + inline std::ostream& operator<<(std::ostream& ostr, const std::pair& p); + +} // namespace misc + +#include -- cgit v1.2.3