|
||||
File indexing completed on 2025-01-18 09:54:46
0001 //----------------------------------*-C++-*----------------------------------// 0002 // Copyright 2020-2024 UT-Battelle, LLC, and other Celeritas developers. 0003 // See the top-level COPYRIGHT file for details. 0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT) 0005 //---------------------------------------------------------------------------// 0006 //! \file corecel/cont/SpanIO.hh 0007 //---------------------------------------------------------------------------// 0008 #pragma once 0009 0010 #include <iomanip> 0011 #include <ostream> 0012 0013 #include "Span.hh" 0014 0015 namespace celeritas 0016 { 0017 //---------------------------------------------------------------------------// 0018 /*! 0019 * Write the elements of span \a s to stream \a os. 0020 */ 0021 template<class T, std::size_t E> 0022 std::ostream& operator<<(std::ostream& os, Span<T, E> const& s) 0023 { 0024 std::streamsize size = s.size(); 0025 std::streamsize width = os.width(); 0026 std::streamsize remainder = 0; 0027 0028 os.width(0); 0029 os << '{'; 0030 if (width > 2 + (size - 1)) 0031 { 0032 // Subtract width for spaces and braces 0033 width -= 2 + (size - 1); 0034 // Individual width is 1/N of that, rounded down, keep remainder 0035 // separate 0036 remainder = width % size; 0037 width = width / size; 0038 } 0039 else 0040 { 0041 width = 0; 0042 } 0043 0044 // First element gets the remainder 0045 os.width(width + remainder); 0046 if (!s.empty()) 0047 { 0048 os << s[0]; 0049 } 0050 0051 for (std::streamsize i = 1; i < size; ++i) 0052 { 0053 os << ','; 0054 os.width(width); 0055 os << s[i]; 0056 } 0057 os << '}'; 0058 0059 return os; 0060 } 0061 0062 //---------------------------------------------------------------------------// 0063 } // namespace celeritas
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |