https://mooseframework.inl.gov
InfixIterator.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 
12 // infix_iterator.h
13 
14 // Lifted from Jerry Coffin's 's prefix_ostream_iterator, no copyright or license
15 
16 #include <ostream>
17 #include <iterator>
18 
19 template <class T, class charT = char, class traits = std::char_traits<charT>>
26 #if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ <= 9)
27  : public std::iterator<std::output_iterator_tag, void, void, void, void>
28 #endif
29 {
30 #if defined(__clang__) || (__GNUC__ > 9)
31  using iterator_category = std::output_iterator_tag;
32 #endif
33 
34  std::basic_ostream<charT, traits> * os;
35  charT const * delimiter;
36  bool first_elem;
37 
38 public:
39  typedef charT char_type;
40  typedef traits traits_type;
41  typedef std::basic_ostream<charT, traits> ostream_type;
43  infix_ostream_iterator(ostream_type & s, charT const * d, bool first = true)
44  : os(&s), delimiter(d), first_elem(first)
45  {
46  }
47  infix_ostream_iterator<T, charT, traits> & operator=(T const & item)
48  {
49  // Here's the only real change from ostream_iterator:
50  // Normally, the '*os << item;' would come before the 'if'.
51  if (!first_elem && delimiter != 0)
52  *os << delimiter;
53  *os << item;
54  first_elem = false;
55  return *this;
56  }
57  infix_ostream_iterator<T, charT, traits> & operator*() { return *this; }
58  infix_ostream_iterator<T, charT, traits> & operator++() { return *this; }
59  infix_ostream_iterator<T, charT, traits> & operator++(int) { return *this; }
60 };
std::basic_ostream< charT, traits > * os
Definition: InfixIterator.h:34
traits traits_type
Definition: InfixIterator.h:40
std::basic_ostream< charT, traits > ostream_type
Definition: InfixIterator.h:41
bool first_elem
Definition: InfixIterator.h:36
infix_ostream_iterator(ostream_type &s)
Definition: InfixIterator.h:42
charT const * delimiter
Definition: InfixIterator.h:35
charT char_type
Definition: InfixIterator.h:39
infix_ostream_iterator< T, charT, traits > & operator=(T const &item)
Definition: InfixIterator.h:47
infix_ostream_iterator< T, charT, traits > & operator*()
Definition: InfixIterator.h:57
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
infix_ostream_iterator< T, charT, traits > & operator++()
Definition: InfixIterator.h:58
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...