Opened 9 years ago

Last modified 8 years ago

#9211 new Feature Requests

fstream types don't have move semantics

Reported by: anonymous Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.54.0 Severity: Problem
Keywords: fstream rvalue move Cc: mail@…

Description

boost::filesystem::ofstream etc. lack move semantics for c++11, so they can't be used as a replacement for std::ofstream etc. if move semantics are required

Change History (6)

comment:1 by viboes, 9 years ago

Type: Bugs → Feature Requests

How is this a bug?

in reply to:  1 comment:2 by anonymous, 9 years ago

Replying to viboes:

How is this a bug?

I understand the filesystem::fstream classes as drop-in replacements for the std ones to support filesystem::path. When a feature that prevents intended operation is missing, I think of it as a bug rather than a feature request, but it's probably a matter of definition.

comment:3 by anonymous, 9 years ago

Here is a use case:

template <typename Stream, typename... Args>
Stream StreamOpen(Args&&... args) {
	Stream stream;
	stream.exceptions(ios::failbit | ios::badbit);
	stream.open(forward<Args>(args)...);
	return stream;
}
auto f1 = StreamOpen<std::ifstream>("filename", std::ios::binary); // succeeds
auto f2 = StreamOpen<boost::filesystem::ifstream>("filename", std::ios::binary); // fails

comment:4 by mail@…, 8 years ago

Cc: mail@… added

comment:5 by anonymous, 8 years ago

Summary: fstream types don't have move semantics → fstream types don't have move semantics or swap method

boost::filesystem::*fstream are missing the swap methods from std::*fstream as well. Since the boost classes don't have any data, would just adding stubs that call the std ones be enough?

comment:6 by anonymous, 8 years ago

Summary: fstream types don't have move semantics or swap method → fstream types don't have move semantics

Actually the boost classes don't need swap methods of their own, they can just use the ones inherited from std:

class myifstream : public boost::filesystem::ifstream {
	myifstream() { }
	myifstream(myifstream&& other) {
		swap(other);
	}
	myifstream& operator=(myifstream&& other) {
		swap(other);
		return *this;
	}
};
auto f3 = StreamOpen<myifstream>("filename", std::ios::binary); // succeeds
Note: See TracTickets for help on using tickets.