[CodeGen] Introduce a VirtRegOrUnit class to hold virtual reg or physical reg unit...
[llvm-project.git] / libcxx / test / std / input.output / file.streams / fstreams / ofstream.cons / path.pass.cpp
blobc62c13d318f13b2627f1f3d442854924f0006f58
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: availability-filesystem-missing
13 // <fstream>
15 // plate <class charT, class traits = char_traits<charT> >
16 // class basic_ofstream
18 // template<class T>
19 // explicit basic_ofstream(const T& s, ios_base::openmode mode = ios_base::out); // Since C++17
20 // Constraints: is_same_v<T, filesystem::path> is true
22 #include <cassert>
23 #include <filesystem>
24 #include <fstream>
25 #include <type_traits>
27 #include "platform_support.h"
28 #include "operator_hijacker.h"
29 #include "test_macros.h"
30 #include "test_iterators.h"
32 namespace fs = std::filesystem;
34 template <class CharT>
35 constexpr bool test_non_convert_to_path() {
36 // String types
37 static_assert(!std::is_constructible_v<std::ofstream, std::basic_string_view<CharT>>);
38 static_assert(!std::is_constructible_v<std::ofstream, const std::basic_string_view<CharT>>);
40 // Char* pointers
41 if constexpr (!std::is_same_v<CharT, char> && !std::is_same_v<CharT, fs::path::value_type>)
42 static_assert(!std::is_constructible_v<std::ofstream, const CharT*>);
44 // Iterators
45 static_assert(!std::is_convertible_v<std::ofstream, cpp17_input_iterator<const CharT*>>);
47 return true;
50 static_assert(test_non_convert_to_path<char>());
52 #if !defined(TEST_HAS_NO_WIDE_CHARACTERS) && !defined(TEST_HAS_OPEN_WITH_WCHAR)
53 static_assert(test_non_convert_to_path<wchar_t>());
54 #endif // !TEST_HAS_NO_WIDE_CHARACTERS && !TEST_HAS_OPEN_WITH_WCHAR
56 #ifndef TEST_HAS_NO_CHAR8_T
57 static_assert(test_non_convert_to_path<char8_t>());
58 #endif // TEST_HAS_NO_CHAR8_T
60 static_assert(test_non_convert_to_path<char16_t>());
61 static_assert(test_non_convert_to_path<char32_t>());
63 int main(int, char**) {
65 static_assert(!std::is_convertible<fs::path, std::ofstream>::value,
66 "ctor should be explicit");
67 static_assert(std::is_constructible<std::ofstream, fs::path const&,
68 std::ios_base::openmode>::value,
69 "");
71 fs::path p = get_temp_file_name();
73 std::ofstream stream(p);
74 stream << 3.25;
77 std::ifstream stream(p);
78 double x = 0;
79 stream >> x;
80 assert(x == 3.25);
82 std::remove(p.string().c_str());
85 std::basic_ofstream<char, operator_hijacker_char_traits<char> > stream(p);
86 stream << "3.25";
89 std::ifstream stream(p);
90 double x = 0;
91 stream >> x;
92 assert(x == 3.25);
94 std::remove(p.string().c_str());
97 std::ofstream stream(p, std::ios_base::out);
98 stream << 3.25;
101 std::ifstream stream(p);
102 double x = 0;
103 stream >> x;
104 assert(x == 3.25);
106 std::remove(p.string().c_str());
109 std::basic_ofstream<char, operator_hijacker_char_traits<char> > stream(p, std::ios_base::out);
110 stream << "3.25";
113 std::ifstream stream(p);
114 double x = 0;
115 stream >> x;
116 assert(x == 3.25);
118 std::remove(p.string().c_str());
120 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
122 std::wofstream stream(p);
123 stream << 3.25;
126 std::wifstream stream(p);
127 double x = 0;
128 stream >> x;
129 assert(x == 3.25);
131 std::remove(p.string().c_str());
134 std::basic_ofstream<wchar_t, operator_hijacker_char_traits<wchar_t> > stream(p);
135 stream << L"3.25";
138 std::wifstream stream(p);
139 double x = 0;
140 stream >> x;
141 assert(x == 3.25);
143 std::remove(p.string().c_str());
146 std::wofstream stream(p, std::ios_base::out);
147 stream << 3.25;
150 std::wifstream stream(p);
151 double x = 0;
152 stream >> x;
153 assert(x == 3.25);
155 std::remove(p.string().c_str());
158 std::basic_ofstream<wchar_t, operator_hijacker_char_traits<wchar_t> > stream(p, std::ios_base::out);
159 stream << L"3.25";
162 std::wifstream stream(p);
163 double x = 0;
164 stream >> x;
165 assert(x == 3.25);
167 std::remove(p.string().c_str());
168 #endif
170 return 0;