diff --git a/iterator.hpp b/iterator.hpp index 0d807c87..3c2e2bef 100644 --- a/iterator.hpp +++ b/iterator.hpp @@ -120,6 +120,39 @@ namespace util { }; + namespace detail { + template + struct infix_t { + const ContainerT &_container; + const CharT *_delimiter; + }; + + template + std::ostream& + operator<< (std::ostream &os, const infix_t &val) + { + std::copy (std::cbegin (val._container), + std::cend (val._container), + infix_iterator (os, val._delimiter)); + return os; + } + + }; + + + /// a helper function that returns an object that will use a + /// util::infix_iterator to output a container's values to an ostream with + /// the given delimiter. + /// + /// reduces boilerplate code required to output lists of things + template + auto + make_infix (const ContainerT &_container, const CharT *_delimiter = ", ") + { + return detail::infix_t { _container, _delimiter }; + }; + + /////////////////////////////////////////////////////////////////////////// template class indices {