www.mooseframework.org
InfixIterator.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 // infix_iterator.h
12 
13 // Lifted from Jerry Coffin's 's prefix_ostream_iterator, no copyright or license
14 
15 #include <ostream>
16 #include <iterator>
17 
18 template <class T, class charT = char, class traits = std::char_traits<charT>>
20  : public std::iterator<std::output_iterator_tag, void, void, void, void>
21 {
22  std::basic_ostream<charT, traits> * os;
23  charT const * delimiter;
24  bool first_elem;
25 
26 public:
27  typedef charT char_type;
28  typedef traits traits_type;
29  typedef std::basic_ostream<charT, traits> ostream_type;
31  infix_ostream_iterator(ostream_type & s, charT const * d, bool first = true)
32  : os(&s), delimiter(d), first_elem(first)
33  {
34  }
36  {
37  // Here's the only real change from ostream_iterator:
38  // Normally, the '*os << item;' would come before the 'if'.
39  if (!first_elem && delimiter != 0)
40  *os << delimiter;
41  *os << item;
42  first_elem = false;
43  return *this;
44  }
48 };
49 
charT const * delimiter
Definition: InfixIterator.h:23
infix_ostream_iterator(ostream_type &s, charT const *d, bool first=true)
Definition: InfixIterator.h:31
infix_ostream_iterator< T, charT, traits > & operator=(T const &item)
Definition: InfixIterator.h:35
infix_ostream_iterator(ostream_type &s)
Definition: InfixIterator.h:30
infix_ostream_iterator< T, charT, traits > & operator*()
Definition: InfixIterator.h:45
std::basic_ostream< charT, traits > ostream_type
Definition: InfixIterator.h:29
std::basic_ostream< charT, traits > * os
Definition: InfixIterator.h:22
infix_ostream_iterator< T, charT, traits > & operator++(int)
Definition: InfixIterator.h:47
infix_ostream_iterator< T, charT, traits > & operator++()
Definition: InfixIterator.h:46