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>>
25 #if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ <= 9)
26  : public std::iterator<std::output_iterator_tag, void, void, void, void>
27 #endif
28 {
29 #if defined(__clang__) || (__GNUC__ > 9)
30  using iterator_category = std::output_iterator_tag;
31 #endif
32 
33  std::basic_ostream<charT, traits> * os;
34  charT const * delimiter;
35  bool first_elem;
36 
37 public:
38  typedef charT char_type;
39  typedef traits traits_type;
40  typedef std::basic_ostream<charT, traits> ostream_type;
42  infix_ostream_iterator(ostream_type & s, charT const * d, bool first = true)
43  : os(&s), delimiter(d), first_elem(first)
44  {
45  }
46  infix_ostream_iterator<T, charT, traits> & operator=(T const & item)
47  {
48  // Here's the only real change from ostream_iterator:
49  // Normally, the '*os << item;' would come before the 'if'.
50  if (!first_elem && delimiter != 0)
51  *os << delimiter;
52  *os << item;
53  first_elem = false;
54  return *this;
55  }
56  infix_ostream_iterator<T, charT, traits> & operator*() { return *this; }
57  infix_ostream_iterator<T, charT, traits> & operator++() { return *this; }
58  infix_ostream_iterator<T, charT, traits> & operator++(int) { return *this; }
59 };
if(subdm)
std::basic_ostream< charT, traits > * os
Definition: InfixIterator.h:33
traits traits_type
Definition: InfixIterator.h:39
std::basic_ostream< charT, traits > ostream_type
Definition: InfixIterator.h:40
bool first_elem
Definition: InfixIterator.h:35
infix_ostream_iterator(ostream_type &s)
Definition: InfixIterator.h:41
charT const * delimiter
Definition: InfixIterator.h:34
charT char_type
Definition: InfixIterator.h:38
infix_ostream_iterator< T, charT, traits > & operator=(T const &item)
Definition: InfixIterator.h:46
infix_ostream_iterator< T, charT, traits > & operator*()
Definition: InfixIterator.h:56
infix_ostream_iterator< T, charT, traits > & operator++()
Definition: InfixIterator.h:57
class infix_ostream_iterator if defined(__GNUC__) &&!defined(__clang__) &&(__GNUC__<
GCC9 currently hits a "no type named &#39;value_type&#39;" error during build if this is removed and iterator...