//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14 // UNSUPPORTED: availability-filesystem-missing // // plate > // class basic_ofstream // template // explicit basic_ofstream(const T& s, ios_base::openmode mode = ios_base::out); // Since C++17 // Constraints: is_same_v is true #include #include #include #include #include "platform_support.h" #include "operator_hijacker.h" #include "test_macros.h" #include "test_iterators.h" namespace fs = std::filesystem; template constexpr bool test_non_convert_to_path() { // String types static_assert(!std::is_constructible_v>); static_assert(!std::is_constructible_v>); // Char* pointers if constexpr (!std::is_same_v && !std::is_same_v) static_assert(!std::is_constructible_v); // Iterators static_assert(!std::is_convertible_v>); return true; } static_assert(test_non_convert_to_path()); #if !defined(TEST_HAS_NO_WIDE_CHARACTERS) && !defined(TEST_HAS_OPEN_WITH_WCHAR) static_assert(test_non_convert_to_path()); #endif // !TEST_HAS_NO_WIDE_CHARACTERS && !TEST_HAS_OPEN_WITH_WCHAR #ifndef TEST_HAS_NO_CHAR8_T static_assert(test_non_convert_to_path()); #endif // TEST_HAS_NO_CHAR8_T static_assert(test_non_convert_to_path()); static_assert(test_non_convert_to_path()); int main(int, char**) { { static_assert(!std::is_convertible::value, "ctor should be explicit"); static_assert(std::is_constructible::value, ""); } fs::path p = get_temp_file_name(); { std::ofstream stream(p); stream << 3.25; } { std::ifstream stream(p); double x = 0; stream >> x; assert(x == 3.25); } std::remove(p.string().c_str()); { std::basic_ofstream > stream(p); stream << "3.25"; } { std::ifstream stream(p); double x = 0; stream >> x; assert(x == 3.25); } std::remove(p.string().c_str()); { std::ofstream stream(p, std::ios_base::out); stream << 3.25; } { std::ifstream stream(p); double x = 0; stream >> x; assert(x == 3.25); } std::remove(p.string().c_str()); { std::basic_ofstream > stream(p, std::ios_base::out); stream << "3.25"; } { std::ifstream stream(p); double x = 0; stream >> x; assert(x == 3.25); } std::remove(p.string().c_str()); #ifndef TEST_HAS_NO_WIDE_CHARACTERS { std::wofstream stream(p); stream << 3.25; } { std::wifstream stream(p); double x = 0; stream >> x; assert(x == 3.25); } std::remove(p.string().c_str()); { std::basic_ofstream > stream(p); stream << L"3.25"; } { std::wifstream stream(p); double x = 0; stream >> x; assert(x == 3.25); } std::remove(p.string().c_str()); { std::wofstream stream(p, std::ios_base::out); stream << 3.25; } { std::wifstream stream(p); double x = 0; stream >> x; assert(x == 3.25); } std::remove(p.string().c_str()); { std::basic_ofstream > stream(p, std::ios_base::out); stream << L"3.25"; } { std::wifstream stream(p); double x = 0; stream >> x; assert(x == 3.25); } std::remove(p.string().c_str()); #endif return 0; }