LCOV - code coverage report
Current view: top level - include/utils - InfixIterator.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 11 11 100.0 %
Date: 2025-07-17 01:28:37 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             : // 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>>
      19             : class infix_ostream_iterator
      20             : /**
      21             :  * GCC9 currently hits a "no type named 'value_type'" error during build if this
      22             :  * is removed and iterator traits are listed within the class corresponding to the
      23             :  * C++17 standard. This preserves use of std::iterator for GCC9 and earlier.
      24             :  */
      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;
      41             :   infix_ostream_iterator(ostream_type & s) : os(&s), delimiter(0), first_elem(true) {}
      42      104143 :   infix_ostream_iterator(ostream_type & s, charT const * d, bool first = true)
      43      104143 :     : os(&s), delimiter(d), first_elem(first)
      44             :   {
      45      104143 :   }
      46      284582 :   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      284582 :     if (!first_elem && delimiter != 0)
      51      180559 :       *os << delimiter;
      52      284582 :     *os << item;
      53      284582 :     first_elem = false;
      54      284582 :     return *this;
      55             :   }
      56      284582 :   infix_ostream_iterator<T, charT, traits> & operator*() { return *this; }
      57      284582 :   infix_ostream_iterator<T, charT, traits> & operator++() { return *this; }
      58             :   infix_ostream_iterator<T, charT, traits> & operator++(int) { return *this; }
      59             : };

Generated by: LCOV version 1.14