Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:29

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #pragma once
0012 
0013 #include <chrono>
0014 #include <iostream>
0015 
0016 #if __cplusplus <= 201703L
0017 
0018 namespace std {
0019   namespace chrono {
0020 
0021     /**
0022      * Helpers to stream duration objects with proper units.
0023      *
0024      * This will become obsolete with C++20:
0025      * https://en.cppreference.com/w/cpp/chrono/duration/operator_ltlt
0026      */
0027     namespace io {
0028       /// Return unit of std::chrono::duration
0029       template <typename T>
0030       inline std::string duration_unit( T ) {
0031         return "";
0032       }
0033 
0034       // template specializations for units of time
0035       template <>
0036       inline std::string duration_unit( std::chrono::nanoseconds ) {
0037         return "ns";
0038       }
0039 
0040       template <>
0041       inline std::string duration_unit( std::chrono::microseconds ) {
0042         return "us";
0043       }
0044 
0045       template <>
0046       inline std::string duration_unit( std::chrono::milliseconds ) {
0047         return "ms";
0048       }
0049 
0050       template <>
0051       inline std::string duration_unit( std::chrono::seconds ) {
0052         return "s";
0053       }
0054 
0055       template <>
0056       inline std::string duration_unit( std::chrono::minutes ) {
0057         return "m";
0058       }
0059 
0060       template <>
0061       inline std::string duration_unit( std::chrono::hours ) {
0062         return "h";
0063       }
0064     } // namespace io
0065 
0066     /// stream operator for std::chrono::duration including unit
0067     template <class Rep, class Period>
0068     std::ostream& operator<<( std::ostream& os, const duration<Rep, Period>& d ) {
0069       os << d.count() << io::duration_unit( d );
0070       return os;
0071     }
0072   } // namespace chrono
0073 } // namespace std
0074 
0075 #endif // C++17