Debian Codegraph @

libcxx/test/std/input.output/file.streams/fstreams/fstream.cons/path.pass.cpp

raw
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 //===----------------------------------------------------------------------===//
8
9 // UNSUPPORTED: c++03, c++11, c++14
10
11 // UNSUPPORTED: availability-filesystem-missing
12
13 // <fstream>
14
15 // plate <class charT, class traits = char_traits<charT> >
16 // class basic_fstream
17
18 // template<class T>
19 // explicit basic_fstream(const T& s, ios_base::openmode mode = ios_base::in); // Since C++17
20 // Constraints: is_same_v<T, filesystem::path> is true
21
22 #include <fstream>
23 #include <filesystem>
24 #include <cassert>
25 #include <type_traits>
26
27 #include "test_macros.h"
28 #include "test_iterators.h"
29 #include "platform_support.h"
30
31 namespace fs = std::filesystem;
32
33 template <class CharT>
34 constexpr bool test_non_convert_to_path() {
35 // String types
36 static_assert(!std::is_constructible_v<std::fstream, std::basic_string_view<CharT>>);
37 static_assert(!std::is_constructible_v<std::fstream, const std::basic_string_view<CharT>>);
38
39 // Char* pointers
40 if constexpr (!std::is_same_v<CharT, char> && !std::is_same_v<CharT, fs::path::value_type>)
41 static_assert(!std::is_constructible_v<std::fstream, const CharT*>);
42
43 // Iterators
44 static_assert(!std::is_convertible_v<std::fstream, cpp17_input_iterator<const CharT*>>);
45
46 return true;
47 }
48
49 static_assert(test_non_convert_to_path<char>());
50
51 #if !defined(TEST_HAS_NO_WIDE_CHARACTERS) && !defined(TEST_HAS_OPEN_WITH_WCHAR)
52 static_assert(test_non_convert_to_path<wchar_t>());
53 #endif // !TEST_HAS_NO_WIDE_CHARACTERS && !TEST_HAS_OPEN_WITH_WCHAR
54
55 #ifndef TEST_HAS_NO_CHAR8_T
56 static_assert(test_non_convert_to_path<char8_t>());
57 #endif // TEST_HAS_NO_CHAR8_T
58
59 static_assert(test_non_convert_to_path<char16_t>());
60 static_assert(test_non_convert_to_path<char32_t>());
61
62 int main(int, char**) {
63 fs::path p = get_temp_file_name();
64 {
65 std::fstream fs(p, std::ios_base::in | std::ios_base::out |
66 std::ios_base::trunc);
67 double x = 0;
68 fs << 3.25;
69 fs.seekg(0);
70 fs >> x;
71 assert(x == 3.25);
72 }
73 std::remove(p.string().c_str());
74
75 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
76 {
77 std::wfstream fs(p, std::ios_base::in | std::ios_base::out |
78 std::ios_base::trunc);
79 double x = 0;
80 fs << 3.25;
81 fs.seekg(0);
82 fs >> x;
83 assert(x == 3.25);
84 }
85 std::remove(p.string().c_str());
86 #endif
87
88 return 0;
89 }