mirror of
https://github.com/fmtlib/fmt.git
synced 2025-04-09 18:45:18 +00:00
* Add a test case: move ostream while holding data * Fix moving ostream while holding data Co-authored-by: Junliang HU <jlhu@cse.cuhk.edu.hk>
This commit is contained in:
parent
7d8c34018e
commit
14848875bf
@ -396,8 +396,10 @@ class ostream final : private detail::buffer<char> {
|
|||||||
ostream(ostream&& other)
|
ostream(ostream&& other)
|
||||||
: detail::buffer<char>(other.data(), other.size(), other.capacity()),
|
: detail::buffer<char>(other.data(), other.size(), other.capacity()),
|
||||||
file_(std::move(other.file_)) {
|
file_(std::move(other.file_)) {
|
||||||
|
other.clear();
|
||||||
other.set(nullptr, 0);
|
other.set(nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
~ostream() {
|
~ostream() {
|
||||||
flush();
|
flush();
|
||||||
delete[] data();
|
delete[] data();
|
||||||
|
@ -293,6 +293,19 @@ TEST(OStreamTest, Move) {
|
|||||||
moved.print("hello");
|
moved.print("hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(OStreamTest, MoveWhileHoldingData) {
|
||||||
|
{
|
||||||
|
fmt::ostream out = fmt::output_file("test-file");
|
||||||
|
out.print("Hello, ");
|
||||||
|
fmt::ostream moved(std::move(out));
|
||||||
|
moved.print("world!\n");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
file in("test-file", file::RDONLY);
|
||||||
|
EXPECT_READ(in, "Hello, world!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST(OStreamTest, Print) {
|
TEST(OStreamTest, Print) {
|
||||||
fmt::ostream out = fmt::output_file("test-file");
|
fmt::ostream out = fmt::output_file("test-file");
|
||||||
out.print("The answer is {}.\n", fmt::join(std::initializer_list<int>{42}, ", "));
|
out.print("The answer is {}.\n", fmt::join(std::initializer_list<int>{42}, ", "));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user