2
0
mirror of https://github.com/boostorg/atomic.git synced 2026-01-19 04:02:09 +00:00
Files
atomic/test/lightweight_test_stream.hpp
Andrey Semashev ab59271bdf Remove some of the pre-C++11 workarounds.
Replaced C++11 emulation macros with proper keywords, replaced typedefs
with using-style type aliases, removed type traits shims that are no
longer needed.
2025-06-11 01:00:52 +03:00

99 lines
2.9 KiB
C++

// Copyright (c) 2020-2025 Andrey Semashev
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ATOMIC_TEST_LIGHTWEIGHT_TEST_STREAM_HPP_INCLUDED_
#define BOOST_ATOMIC_TEST_LIGHTWEIGHT_TEST_STREAM_HPP_INCLUDED_
#include <iostream>
#include <boost/config.hpp>
struct test_stream_type
{
using ios_base_manip = std::ios_base& (std::ios_base&);
using basic_ios_manip = std::basic_ios< char, std::char_traits< char > >& (std::basic_ios< char, std::char_traits< char > >&);
using stream_manip = std::ostream& (std::ostream&);
template< typename T >
test_stream_type const& operator<< (T const& value) const
{
std::cerr << value;
return *this;
}
test_stream_type const& operator<< (ios_base_manip* manip) const
{
std::cerr << manip;
return *this;
}
test_stream_type const& operator<< (basic_ios_manip* manip) const
{
std::cerr << manip;
return *this;
}
test_stream_type const& operator<< (stream_manip* manip) const
{
std::cerr << manip;
return *this;
}
// Make sure characters are printed as numbers if tests fail
test_stream_type const& operator<< (char value) const
{
std::cerr << static_cast< int >(value);
return *this;
}
test_stream_type const& operator<< (signed char value) const
{
std::cerr << static_cast< int >(value);
return *this;
}
test_stream_type const& operator<< (unsigned char value) const
{
std::cerr << static_cast< unsigned int >(value);
return *this;
}
test_stream_type const& operator<< (short value) const
{
std::cerr << static_cast< int >(value);
return *this;
}
test_stream_type const& operator<< (unsigned short value) const
{
std::cerr << static_cast< unsigned int >(value);
return *this;
}
#if defined(BOOST_HAS_INT128)
// Some GCC versions don't provide output operators for __int128
test_stream_type const& operator<< (boost::int128_type const& v) const
{
std::cerr << static_cast< long long >(v);
return *this;
}
test_stream_type const& operator<< (boost::uint128_type const& v) const
{
std::cerr << static_cast< unsigned long long >(v);
return *this;
}
#endif // defined(BOOST_HAS_INT128)
#if defined(BOOST_HAS_FLOAT128)
// libstdc++ does not provide output operators for __float128
test_stream_type const& operator<< (boost::float128_type const& v) const
{
std::cerr << static_cast< double >(v);
return *this;
}
#endif // defined(BOOST_HAS_FLOAT128)
};
const test_stream_type test_stream = {};
#define BOOST_LIGHTWEIGHT_TEST_OSTREAM test_stream
#include <boost/core/lightweight_test.hpp>
#endif // BOOST_ATOMIC_TEST_LIGHTWEIGHT_TEST_STREAM_HPP_INCLUDED_