Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:06

0001 
0002 //              Copyright Catch2 Authors
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //   (See accompanying file LICENSE.txt or copy at
0005 //        https://www.boost.org/LICENSE_1_0.txt)
0006 
0007 // SPDX-License-Identifier: BSL-1.0
0008 #ifndef CATCH_REUSABLE_STRING_STREAM_HPP_INCLUDED
0009 #define CATCH_REUSABLE_STRING_STREAM_HPP_INCLUDED
0010 
0011 #include <catch2/internal/catch_noncopyable.hpp>
0012 
0013 #include <iosfwd>
0014 #include <cstddef>
0015 #include <ostream>
0016 #include <string>
0017 
0018 namespace Catch {
0019 
0020     class ReusableStringStream : Detail::NonCopyable {
0021         std::size_t m_index;
0022         std::ostream* m_oss;
0023     public:
0024         ReusableStringStream();
0025         ~ReusableStringStream();
0026 
0027         //! Returns the serialized state
0028         std::string str() const;
0029         //! Sets internal state to `str`
0030         void str(std::string const& str);
0031 
0032 #if defined(__GNUC__) && !defined(__clang__)
0033 #pragma GCC diagnostic push
0034 // Old versions of GCC do not understand -Wnonnull-compare
0035 #pragma GCC diagnostic ignored "-Wpragmas"
0036 // Streaming a function pointer triggers Waddress and Wnonnull-compare
0037 // on GCC, because it implicitly converts it to bool and then decides
0038 // that the check it uses (a? true : false) is tautological and cannot
0039 // be null...
0040 #pragma GCC diagnostic ignored "-Waddress"
0041 #pragma GCC diagnostic ignored "-Wnonnull-compare"
0042 #endif
0043 
0044         template<typename T>
0045         auto operator << ( T const& value ) -> ReusableStringStream& {
0046             *m_oss << value;
0047             return *this;
0048         }
0049 
0050 #if defined(__GNUC__) && !defined(__clang__)
0051 #pragma GCC diagnostic pop
0052 #endif
0053         auto get() -> std::ostream& { return *m_oss; }
0054     };
0055 }
0056 
0057 #endif // CATCH_REUSABLE_STRING_STREAM_HPP_INCLUDED