]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/6.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_ostream / inserters_other / char / 6.cc
CommitLineData
a7da4881
VV
1// { dg-do run { target c++11 } }
2
99dee823 3// Copyright (C) 2016-2021 Free Software Foundation, Inc.
a7da4881
VV
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
19
20// 27.6.2.5.3 basic_ostream manipulator inserters
21
22#include <sstream>
23
24struct X {};
25std::ostream& operator<<(std::ostream&, const X&) = delete;
26
27struct Y {};
28std::ostream& operator<<(std::ostream& os, const Y&) {return os;}
29std::ostream& operator<<(std::ostream&& os, const Y&) {return os;}
30
31struct Z{};
32
33template <class T>
34auto f(T&&) -> decltype(void(std::declval<std::ostream&>()
35 << std::declval<T&&>()),
36 std::true_type());
37
38std::false_type f(...);
39
40template <class T>
41auto g(T&&) -> decltype(void(std::declval<std::ostream&&>()
42 << std::declval<T&&>()),
43 std::true_type());
44
45std::false_type g(...);
46
47void test01()
48{
49 Y y;
50 std::ostringstream os;
51 os << y;
52 os << Y();
53 std::ostringstream() << y;
54 std::ostringstream() << Y();
55 static_assert(!std::__is_insertable<std::ostream&, X&>::value, "");
56 static_assert(!std::__is_insertable<std::ostream&&, X&>::value, "");
57 static_assert(!std::__is_insertable<std::ostream&, X&&>::value, "");
58 static_assert(!std::__is_insertable<std::ostream&&, X&&>::value, "");
59 static_assert(std::__is_insertable<std::ostream&, Y&>::value, "");
60 static_assert(std::__is_insertable<std::ostream&&, Y&&>::value, "");
61 static_assert(std::__is_insertable<std::ostream&, Y&>::value, "");
62 static_assert(std::__is_insertable<std::ostream&&, Y&&>::value, "");
63 static_assert(!std::__is_insertable<std::ostream&, Z&>::value, "");
64 static_assert(!std::__is_insertable<std::ostream&&, Z&>::value, "");
65 static_assert(!std::__is_insertable<std::ostream&, Z&&>::value, "");
66 static_assert(!std::__is_insertable<std::ostream&&, Z&&>::value, "");
67 static_assert(std::is_same<decltype(f(std::declval<X&>())),
68 std::false_type>::value, "");
69 static_assert(std::is_same<decltype(f(std::declval<X&&>())),
70 std::false_type>::value, "");
71 static_assert(std::is_same<decltype(f(std::declval<Y&>())),
72 std::true_type>::value, "");
73 static_assert(std::is_same<decltype(f(std::declval<Y&&>())),
74 std::true_type>::value, "");
75 static_assert(std::is_same<decltype(f(std::declval<Z&>())),
76 std::false_type>::value, "");
77 static_assert(std::is_same<decltype(f(std::declval<Z&&>())),
78 std::false_type>::value, "");
79 static_assert(std::is_same<decltype(g(std::declval<X&>())),
80 std::false_type>::value, "");
81 static_assert(std::is_same<decltype(g(std::declval<X&&>())),
82 std::false_type>::value, "");
83 static_assert(std::is_same<decltype(g(std::declval<Y&>())),
84 std::true_type>::value, "");
85 static_assert(std::is_same<decltype(g(std::declval<Y&&>())),
86 std::true_type>::value, "");
87 static_assert(std::is_same<decltype(g(std::declval<Z&>())),
88 std::false_type>::value, "");
89 static_assert(std::is_same<decltype(g(std::declval<Z&&>())),
90 std::false_type>::value, "");
91}
92
93int main()
94{
95 test01();
96}