• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  Copyright (c) 2020 Andrey Semashev
2 //
3 //  Distributed under the Boost Software License, Version 1.0.
4 //  See accompanying file LICENSE_1_0.txt or copy at
5 //  http://www.boost.org/LICENSE_1_0.txt)
6 
7 #ifndef BOOST_ATOMIC_TEST_LIGHTWEIGHT_TEST_STREAM_HPP_INCLUDED_
8 #define BOOST_ATOMIC_TEST_LIGHTWEIGHT_TEST_STREAM_HPP_INCLUDED_
9 
10 #include <iostream>
11 #include <boost/config.hpp>
12 
13 struct test_stream_type
14 {
15     typedef std::ios_base& (*ios_base_manip)(std::ios_base&);
16     typedef std::basic_ios< char, std::char_traits< char > >& (*basic_ios_manip)(std::basic_ios< char, std::char_traits< char > >&);
17     typedef std::ostream& (*stream_manip)(std::ostream&);
18 
19     template< typename T >
operator <<test_stream_type20     test_stream_type const& operator<< (T const& value) const
21     {
22         std::cerr << value;
23         return *this;
24     }
25 
operator <<test_stream_type26     test_stream_type const& operator<< (ios_base_manip manip) const
27     {
28         std::cerr << manip;
29         return *this;
30     }
operator <<test_stream_type31     test_stream_type const& operator<< (basic_ios_manip manip) const
32     {
33         std::cerr << manip;
34         return *this;
35     }
operator <<test_stream_type36     test_stream_type const& operator<< (stream_manip manip) const
37     {
38         std::cerr << manip;
39         return *this;
40     }
41 
42     // Make sure characters are printed as numbers if tests fail
operator <<test_stream_type43     test_stream_type const& operator<< (char value) const
44     {
45         std::cerr << static_cast< int >(value);
46         return *this;
47     }
operator <<test_stream_type48     test_stream_type const& operator<< (signed char value) const
49     {
50         std::cerr << static_cast< int >(value);
51         return *this;
52     }
operator <<test_stream_type53     test_stream_type const& operator<< (unsigned char value) const
54     {
55         std::cerr << static_cast< unsigned int >(value);
56         return *this;
57     }
operator <<test_stream_type58     test_stream_type const& operator<< (short value) const
59     {
60         std::cerr << static_cast< int >(value);
61         return *this;
62     }
operator <<test_stream_type63     test_stream_type const& operator<< (unsigned short value) const
64     {
65         std::cerr << static_cast< unsigned int >(value);
66         return *this;
67     }
68 
69 #if defined(BOOST_HAS_INT128)
70     // Some GCC versions don't provide output operators for __int128
operator <<test_stream_type71     test_stream_type const& operator<< (boost::int128_type const& v) const
72     {
73         std::cerr << static_cast< long long >(v);
74         return *this;
75     }
operator <<test_stream_type76     test_stream_type const& operator<< (boost::uint128_type const& v) const
77     {
78         std::cerr << static_cast< unsigned long long >(v);
79         return *this;
80     }
81 #endif // defined(BOOST_HAS_INT128)
82 #if defined(BOOST_HAS_FLOAT128)
83     // libstdc++ does not provide output operators for __float128
operator <<test_stream_type84     test_stream_type const& operator<< (boost::float128_type const& v) const
85     {
86         std::cerr << static_cast< double >(v);
87         return *this;
88     }
89 #endif // defined(BOOST_HAS_FLOAT128)
90 };
91 
92 const test_stream_type test_stream = {};
93 
94 #define BOOST_LIGHTWEIGHT_TEST_OSTREAM test_stream
95 
96 #include <boost/core/lightweight_test.hpp>
97 
98 #endif // BOOST_ATOMIC_TEST_LIGHTWEIGHT_TEST_STREAM_HPP_INCLUDED_
99