LCOV - code coverage report
Current view: top level - include/utils - InfixIterator.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 11 11 100.0 %
Date: 2026-05-29 20:35:17 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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>>
      20             : class infix_ostream_iterator
      21             : /**
      22             :  * GCC9 currently hits a "no type named 'value_type'" error during build if this
      23             :  * is removed and iterator traits are listed within the class corresponding to the
      24             :  * C++17 standard. This preserves use of std::iterator for GCC9 and earlier.
      25             :  */
      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;
      42             :   infix_ostream_iterator(ostream_type & s) : os(&s), delimiter(0), first_elem(true) {}
      43      669923 :   infix_ostream_iterator(ostream_type & s, charT const * d, bool first = true)
      44      668959 :     : os(&s), delimiter(d), first_elem(first)
      45             :   {
      46      669923 :   }
      47     1991422 :   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     1991422 :     if (!first_elem && delimiter != 0)
      52     1321633 :       *os << delimiter;
      53     1991422 :     *os << item;
      54     1991422 :     first_elem = false;
      55     1991422 :     return *this;
      56             :   }
      57     1991422 :   infix_ostream_iterator<T, charT, traits> & operator*() { return *this; }
      58     1991422 :   infix_ostream_iterator<T, charT, traits> & operator++() { return *this; }
      59             :   infix_ostream_iterator<T, charT, traits> & operator++(int) { return *this; }
      60             : };

Generated by: LCOV version 1.14